1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
32 #include "SMESH_MeshEditor_i.hxx"
34 #include "SMDS_Mesh0DElement.hxx"
35 #include "SMDS_MeshEdge.hxx"
36 #include "SMDS_MeshFace.hxx"
37 #include "SMDS_MeshVolume.hxx"
38 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
39 #include "SMESH_subMeshEventListener.hxx"
40 #include "SMESH_Gen_i.hxx"
41 #include "SMESH_Filter_i.hxx"
42 #include "SMESH_subMesh_i.hxx"
43 #include "SMESH_Group_i.hxx"
44 #include "SMESH_PythonDump.hxx"
45 #include "SMESH_ControlsDef.hxx"
47 #include "utilities.h"
48 #include "Utils_ExceptHandlers.hxx"
49 #include "Utils_CorbaException.hxx"
51 #include <BRepAdaptor_Surface.hxx>
52 #include <BRep_Tool.hxx>
53 #include <TopExp_Explorer.hxx>
55 #include <TopoDS_Edge.hxx>
56 #include <TopoDS_Face.hxx>
61 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
65 #include <Standard_Failure.hxx>
68 #include <Standard_ErrorHandler.hxx>
74 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
77 using SMESH::TPythonDump;
81 //=============================================================================
83 * \brief Mesh to apply modifications for preview purposes
85 //=============================================================================
87 struct TPreviewMesh: public SMESH_Mesh
89 SMDSAbs_ElementType myPreviewType; // type to show
91 TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
92 _isShapeToMesh = (_id =_studyId =_idDoc = 0);
93 _myMeshDS = new SMESHDS_Mesh( _id, true );
94 myPreviewType = previewElements;
97 virtual ~TPreviewMesh() { delete _myMeshDS; }
98 //!< Copy a set of elements
99 void Copy(const TIDSortedElemSet & theElements,
100 TIDSortedElemSet& theCopyElements,
101 SMDSAbs_ElementType theSelectType = SMDSAbs_All,
102 SMDSAbs_ElementType theAvoidType = SMDSAbs_All)
104 // loop on theIDsOfElements
105 TIDSortedElemSet::const_iterator eIt = theElements.begin();
106 for ( ; eIt != theElements.end(); ++eIt )
108 const SMDS_MeshElement* anElem = *eIt;
109 if ( !anElem ) continue;
110 SMDSAbs_ElementType type = anElem->GetType();
111 if ( type == theAvoidType ||
112 ( theSelectType != SMDSAbs_All && type != theSelectType ))
115 if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
116 theCopyElements.insert( theCopyElements.end(), anElemCopy );
120 SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
122 // copy element nodes
123 int anElemNbNodes = anElem->NbNodes();
124 vector< int > anElemNodesID( anElemNbNodes ) ;
125 SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
126 for ( int i = 0; itElemNodes->more(); i++)
128 const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
130 anElemNodesID[i] = anElemNode->GetID();
133 // creates a corresponding element on copied nodes
134 SMDS_MeshElement* anElemCopy = 0;
135 if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
137 const SMDS_PolyhedralVolumeOfNodes* ph =
138 dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
140 anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
141 (anElemNodesID, ph->GetQuanities(),anElem->GetID());
144 anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
151 SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
153 return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(),
154 anElemNode->GetID());
156 };// struct TPreviewMesh
158 static SMESH_NodeSearcher * theNodeSearcher = 0;
159 static SMESH_ElementSearcher * theElementSearcher = 0;
161 //=============================================================================
163 * \brief Deleter of theNodeSearcher at any compute event occured
165 //=============================================================================
167 struct TSearchersDeleter : public SMESH_subMeshEventListener
171 TSearchersDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
173 //!< Delete theNodeSearcher
176 if ( theNodeSearcher ) delete theNodeSearcher; theNodeSearcher = 0;
177 if ( theElementSearcher ) delete theElementSearcher; theElementSearcher = 0;
179 typedef map < int, SMESH_subMesh * > TDependsOnMap;
180 //!< The meshod called by submesh: do my main job
181 void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
182 SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
184 if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
186 Unset( sm->GetFather() );
189 //!< set self on all submeshes and delete theNodeSearcher if other mesh is set
190 void Set(SMESH_Mesh* mesh)
192 if ( myMesh != mesh )
199 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
200 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
201 TDependsOnMap::const_iterator sm;
202 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
203 sm->second->SetEventListener( this, 0, sm->second );
207 //!< delete self from all submeshes
208 void Unset(SMESH_Mesh* mesh)
210 if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
211 const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
212 TDependsOnMap::const_iterator sm;
213 for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
214 sm->second->DeleteEventListener( this );
219 } theSearchersDeleter;
221 TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
223 TCollection_AsciiString typeStr;
224 switch ( theMirrorType ) {
225 case SMESH::SMESH_MeshEditor::POINT:
226 typeStr = "SMESH.SMESH_MeshEditor.POINT";
228 case SMESH::SMESH_MeshEditor::AXIS:
229 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
232 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
236 //================================================================================
238 * \brief function for conversion long_array to TIDSortedElemSet
239 * \param IDs - array of IDs
240 * \param aMesh - mesh
241 * \param aMap - collection to fill
242 * \param aType - element type
244 //================================================================================
246 void arrayToSet(const SMESH::long_array & IDs,
247 const SMESHDS_Mesh* aMesh,
248 TIDSortedElemSet& aMap,
249 const SMDSAbs_ElementType aType = SMDSAbs_All )
251 for (int i=0; i<IDs.length(); i++) {
252 CORBA::Long ind = IDs[i];
253 const SMDS_MeshElement * elem =
254 (aType == SMDSAbs_Node ? aMesh->FindNode(ind) : aMesh->FindElement(ind));
255 if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
259 //================================================================================
261 * \brief Retrieve elements of given type from SMESH_IDSource
263 //================================================================================
265 bool idSourceToSet(SMESH::SMESH_IDSource_ptr theIDSource,
266 const SMESHDS_Mesh* theMeshDS,
267 TIDSortedElemSet& theElemSet,
268 const SMDSAbs_ElementType theType,
269 const bool emptyIfIsMesh=false)
272 if ( CORBA::is_nil( theIDSource ) )
274 if ( emptyIfIsMesh && SMESH::DownCast<SMESH_Mesh_i*>( theIDSource ))
277 SMESH::long_array_var anIDs = theIDSource->GetIDs();
278 if ( anIDs->length() == 0 )
280 SMESH::array_of_ElementType_var types = theIDSource->GetTypes();
281 if ( types->length() == 1 && types[0] == SMESH::NODE ) // group of nodes
283 if ( theType == SMDSAbs_All || theType == SMDSAbs_Node )
284 arrayToSet( anIDs, theMeshDS, theElemSet, SMDSAbs_Node );
290 arrayToSet( anIDs, theMeshDS, theElemSet, theType);
294 //================================================================================
296 * \brief Retrieve nodes from SMESH_IDSource
298 //================================================================================
300 void idSourceToNodeSet(SMESH::SMESH_IDSource_ptr theObject,
301 const SMESHDS_Mesh* theMeshDS,
302 TIDSortedNodeSet& theNodeSet)
305 if ( CORBA::is_nil( theObject ) )
307 SMESH::array_of_ElementType_var types = theObject->GetTypes();
308 SMESH::long_array_var aElementsId = theObject->GetIDs();
309 if ( types->length() == 1 && types[0] == SMESH::NODE)
311 for(int i = 0; i < aElementsId->length(); i++)
312 if ( const SMDS_MeshNode * n = theMeshDS->FindNode( aElementsId[i] ))
313 theNodeSet.insert( theNodeSet.end(), n);
316 for(int i = 0; i < aElementsId->length(); i++)
317 if( const SMDS_MeshElement * elem = theMeshDS->FindElement( aElementsId[i] ))
318 theNodeSet.insert( elem->begin_nodes(), elem->end_nodes());
323 //=============================================================================
327 //=============================================================================
329 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
332 myMesh = & theMesh->GetImpl();
333 myPreviewMode = isPreview;
336 //================================================================================
340 //================================================================================
342 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
346 //================================================================================
348 * \brief Clear members
350 //================================================================================
352 void SMESH_MeshEditor_i::initData(bool deleteSearchers)
354 if ( myPreviewMode ) {
355 myPreviewData = new SMESH::MeshPreviewStruct();
358 myLastCreatedElems = new SMESH::long_array();
359 myLastCreatedNodes = new SMESH::long_array();
360 if ( deleteSearchers )
361 TSearchersDeleter::Delete();
365 //=======================================================================
366 //function : MakeIDSource
367 //purpose : Wrap a sequence of ids in a SMESH_IDSource
368 //=======================================================================
370 struct _IDSource : public POA_SMESH::SMESH_IDSource
372 SMESH::long_array _ids;
373 SMESH::ElementType _type;
374 SMESH::long_array* GetIDs() { return new SMESH::long_array( _ids ); }
375 SMESH::long_array* GetMeshInfo() { return 0; }
376 SMESH::array_of_ElementType* GetTypes()
378 SMESH::array_of_ElementType_var types = new SMESH::array_of_ElementType;
381 return types._retn();
385 SMESH::SMESH_IDSource_ptr SMESH_MeshEditor_i::MakeIDSource(const SMESH::long_array& ids,
386 SMESH::ElementType type)
388 _IDSource* anIDSource = new _IDSource;
389 anIDSource->_ids = ids;
390 anIDSource->_type = type;
391 SMESH::SMESH_IDSource_var anIDSourceVar = anIDSource->_this();
393 return anIDSourceVar._retn();
396 //=============================================================================
400 //=============================================================================
403 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
407 ::SMESH_MeshEditor anEditor( myMesh );
410 for (int i = 0; i < IDsOfElements.length(); i++)
411 IdList.push_back( IDsOfElements[i] );
413 // Update Python script
414 TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
416 if ( IDsOfElements.length() )
417 myMesh->SetIsModified( true ); // issue 0020693
420 return anEditor.Remove( IdList, false );
423 //=============================================================================
427 //=============================================================================
429 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
433 ::SMESH_MeshEditor anEditor( myMesh );
435 for (int i = 0; i < IDsOfNodes.length(); i++)
436 IdList.push_back( IDsOfNodes[i] );
438 // Update Python script
439 TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
441 if ( IDsOfNodes.length() )
442 myMesh->SetIsModified( true ); // issue 0020693
444 return anEditor.Remove( IdList, true );
447 //=============================================================================
451 //=============================================================================
453 CORBA::Long SMESH_MeshEditor_i::RemoveOrphanNodes()
457 ::SMESH_MeshEditor anEditor( myMesh );
459 // Update Python script
460 TPythonDump() << "nbRemoved = " << this << ".RemoveOrphanNodes()";
462 // Create filter to find all orphan nodes
463 SMESH::Controls::Filter::TIdSequence seq;
464 SMESH::Controls::PredicatePtr predicate( new SMESH::Controls::FreeNodes() );
465 SMESH::Controls::Filter::GetElementsId( GetMeshDS(), predicate, seq );
467 // remove orphan nodes (if there are any)
469 for ( int i = 0; i < seq.size(); i++ )
470 IdList.push_back( seq[i] );
473 myMesh->SetIsModified( true );
475 return anEditor.Remove( IdList, true );
478 //=============================================================================
482 //=============================================================================
484 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
485 CORBA::Double y, CORBA::Double z)
489 const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
491 // Update Python script
492 TPythonDump() << "nodeID = " << this << ".AddNode( "
493 << x << ", " << y << ", " << z << " )";
495 myMesh->SetIsModified( true ); // issue 0020693
500 //=============================================================================
504 //=============================================================================
505 CORBA::Long SMESH_MeshEditor_i::Add0DElement(CORBA::Long IDOfNode)
509 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(IDOfNode);
510 SMDS_MeshElement* elem = GetMeshDS()->Add0DElement(aNode);
512 // Update Python script
513 TPythonDump() << "elem0d = " << this << ".Add0DElement( " << IDOfNode <<" )";
515 myMesh->SetIsModified( true ); // issue 0020693
518 return elem->GetID();
523 //=============================================================================
527 //=============================================================================
529 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
533 int NbNodes = IDsOfNodes.length();
534 SMDS_MeshElement* elem = 0;
537 CORBA::Long index1 = IDsOfNodes[0];
538 CORBA::Long index2 = IDsOfNodes[1];
539 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
541 // Update Python script
542 TPythonDump() << "edge = " << this << ".AddEdge([ "
543 << index1 << ", " << index2 <<" ])";
546 CORBA::Long n1 = IDsOfNodes[0];
547 CORBA::Long n2 = IDsOfNodes[1];
548 CORBA::Long n12 = IDsOfNodes[2];
549 elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
550 GetMeshDS()->FindNode(n2),
551 GetMeshDS()->FindNode(n12));
552 // Update Python script
553 TPythonDump() << "edgeID = " << this << ".AddEdge([ "
554 <<n1<<", "<<n2<<", "<<n12<<" ])";
558 return myMesh->SetIsModified( true ), elem->GetID();
563 //=============================================================================
567 //=============================================================================
569 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
573 int NbNodes = IDsOfNodes.length();
579 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
580 for (int i = 0; i < NbNodes; i++)
581 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
583 SMDS_MeshElement* elem = 0;
585 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
587 else if (NbNodes == 4) {
588 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
590 else if (NbNodes == 6) {
591 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
594 else if (NbNodes == 8) {
595 elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
596 nodes[4], nodes[5], nodes[6], nodes[7]);
598 else if (NbNodes > 2) {
599 elem = GetMeshDS()->AddPolygonalFace(nodes);
602 // Update Python script
603 TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
606 return myMesh->SetIsModified( true ), elem->GetID();
611 //=============================================================================
615 //=============================================================================
616 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace (const SMESH::long_array & IDsOfNodes)
620 int NbNodes = IDsOfNodes.length();
621 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
622 for (int i = 0; i < NbNodes; i++)
623 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
625 const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
627 // Update Python script
628 TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
630 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
633 //=============================================================================
637 //=============================================================================
639 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
643 int NbNodes = IDsOfNodes.length();
644 vector< const SMDS_MeshNode*> n(NbNodes);
645 for(int i=0;i<NbNodes;i++)
646 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
648 SMDS_MeshElement* elem = 0;
651 case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
652 case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
653 case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
654 case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
655 case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
656 n[6],n[7],n[8],n[9]);
658 case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
659 n[7],n[8],n[9],n[10],n[11],n[12]);
661 case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
662 n[9],n[10],n[11],n[12],n[13],n[14]);
664 case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
665 n[8],n[9],n[10],n[11],n[12],n[13],n[14],
666 n[15],n[16],n[17],n[18],n[19]);
670 // Update Python script
671 TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
674 return myMesh->SetIsModified( true ), elem->GetID();
679 //=============================================================================
681 * AddPolyhedralVolume
683 //=============================================================================
684 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume (const SMESH::long_array & IDsOfNodes,
685 const SMESH::long_array & Quantities)
689 int NbNodes = IDsOfNodes.length();
690 std::vector<const SMDS_MeshNode*> n (NbNodes);
691 for (int i = 0; i < NbNodes; i++)
692 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
694 int NbFaces = Quantities.length();
695 std::vector<int> q (NbFaces);
696 for (int j = 0; j < NbFaces; j++)
697 q[j] = Quantities[j];
699 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
701 // Update Python script
702 TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
703 << IDsOfNodes << ", " << Quantities << " )";
705 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
708 //=============================================================================
710 * AddPolyhedralVolumeByFaces
712 //=============================================================================
713 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces (const SMESH::long_array & IdsOfFaces)
717 int NbFaces = IdsOfFaces.length();
718 std::vector<const SMDS_MeshNode*> poly_nodes;
719 std::vector<int> quantities (NbFaces);
721 for (int i = 0; i < NbFaces; i++) {
722 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
723 quantities[i] = aFace->NbNodes();
725 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
727 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
731 const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
733 // Update Python script
734 TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
735 << IdsOfFaces << " )";
737 return elem ? ( myMesh->SetIsModified( true ), elem->GetID()) : 0;
740 //=============================================================================
742 * \brief Bind a node to a vertex
743 * \param NodeID - node ID
744 * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
745 * \retval boolean - false if NodeID or VertexID is invalid
747 //=============================================================================
749 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
750 throw (SALOME::SALOME_Exception)
752 Unexpect aCatch(SALOME_SalomeException);
754 SMESHDS_Mesh * mesh = GetMeshDS();
755 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
757 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
759 if ( mesh->MaxShapeIndex() < VertexID )
760 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
762 TopoDS_Shape shape = mesh->IndexToShape( VertexID );
763 if ( shape.ShapeType() != TopAbs_VERTEX )
764 THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
766 mesh->SetNodeOnVertex( node, VertexID );
768 myMesh->SetIsModified( true );
771 //=============================================================================
773 * \brief Store node position on an edge
774 * \param NodeID - node ID
775 * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
776 * \param paramOnEdge - parameter on edge where the node is located
777 * \retval boolean - false if any parameter is invalid
779 //=============================================================================
781 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
782 CORBA::Double paramOnEdge)
783 throw (SALOME::SALOME_Exception)
785 Unexpect aCatch(SALOME_SalomeException);
787 SMESHDS_Mesh * mesh = GetMeshDS();
788 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
790 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
792 if ( mesh->MaxShapeIndex() < EdgeID )
793 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
795 TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
796 if ( shape.ShapeType() != TopAbs_EDGE )
797 THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
800 BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
801 if ( paramOnEdge < f || paramOnEdge > l )
802 THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
804 mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
806 myMesh->SetIsModified( true );
809 //=============================================================================
811 * \brief Store node position on a face
812 * \param NodeID - node ID
813 * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
814 * \param u - U parameter on face where the node is located
815 * \param v - V parameter on face where the node is located
816 * \retval boolean - false if any parameter is invalid
818 //=============================================================================
820 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
821 CORBA::Double u, CORBA::Double v)
822 throw (SALOME::SALOME_Exception)
824 Unexpect aCatch(SALOME_SalomeException);
826 SMESHDS_Mesh * mesh = GetMeshDS();
827 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
829 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
831 if ( mesh->MaxShapeIndex() < FaceID )
832 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
834 TopoDS_Shape shape = mesh->IndexToShape( FaceID );
835 if ( shape.ShapeType() != TopAbs_FACE )
836 THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
838 BRepAdaptor_Surface surf( TopoDS::Face( shape ));
839 bool isOut = ( u < surf.FirstUParameter() ||
840 u > surf.LastUParameter() ||
841 v < surf.FirstVParameter() ||
842 v > surf.LastVParameter() );
846 MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
847 << " u( " << surf.FirstUParameter()
848 << "," << surf.LastUParameter()
849 << ") v( " << surf.FirstVParameter()
850 << "," << surf.LastVParameter() << ")" );
852 THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
855 mesh->SetNodeOnFace( node, FaceID, u, v );
857 myMesh->SetIsModified( true );
860 //=============================================================================
862 * \brief Bind a node to a solid
863 * \param NodeID - node ID
864 * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
865 * \retval boolean - false if NodeID or SolidID is invalid
867 //=============================================================================
869 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
870 throw (SALOME::SALOME_Exception)
872 Unexpect aCatch(SALOME_SalomeException);
874 SMESHDS_Mesh * mesh = GetMeshDS();
875 SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
877 THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
879 if ( mesh->MaxShapeIndex() < SolidID )
880 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
882 TopoDS_Shape shape = mesh->IndexToShape( SolidID );
883 if ( shape.ShapeType() != TopAbs_SOLID &&
884 shape.ShapeType() != TopAbs_SHELL)
885 THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
887 mesh->SetNodeInVolume( node, SolidID );
889 // myMesh->SetIsModified( true ); - SetNodeInVolume() can't prevent re-compute, I believe
892 //=============================================================================
894 * \brief Bind an element to a shape
895 * \param ElementID - element ID
896 * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
897 * \retval boolean - false if ElementID or ShapeID is invalid
899 //=============================================================================
901 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
903 throw (SALOME::SALOME_Exception)
905 Unexpect aCatch(SALOME_SalomeException);
907 SMESHDS_Mesh * mesh = GetMeshDS();
908 SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
910 THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
912 if ( mesh->MaxShapeIndex() < ShapeID )
913 THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
915 TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
916 if ( shape.ShapeType() != TopAbs_EDGE &&
917 shape.ShapeType() != TopAbs_FACE &&
918 shape.ShapeType() != TopAbs_SOLID &&
919 shape.ShapeType() != TopAbs_SHELL )
920 THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
922 mesh->SetMeshElementOnShape( elem, ShapeID );
924 myMesh->SetIsModified( true );
927 //=============================================================================
931 //=============================================================================
933 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
938 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
939 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
943 // Update Python script
944 TPythonDump() << "isDone = " << this << ".InverseDiag( "
945 << NodeID1 << ", " << NodeID2 << " )";
947 myMesh->SetIsModified( true );
949 ::SMESH_MeshEditor aMeshEditor( myMesh );
950 return aMeshEditor.InverseDiag ( n1, n2 );
953 //=============================================================================
957 //=============================================================================
959 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
964 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
965 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
969 // Update Python script
970 TPythonDump() << "isDone = " << this << ".DeleteDiag( "
971 << NodeID1 << ", " << NodeID2 << " )";
973 ::SMESH_MeshEditor aMeshEditor( myMesh );
975 bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
978 myMesh->SetIsModified( true ); // issue 0020693
980 storeResult(aMeshEditor);
985 //=============================================================================
989 //=============================================================================
991 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
995 ::SMESH_MeshEditor anEditor( myMesh );
996 for (int i = 0; i < IDsOfElements.length(); i++)
998 CORBA::Long index = IDsOfElements[i];
999 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
1001 anEditor.Reorient( elem );
1003 // Update Python script
1004 TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
1006 if ( IDsOfElements.length() )
1007 myMesh->SetIsModified( true ); // issue 0020693
1013 //=============================================================================
1017 //=============================================================================
1019 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
1023 TPythonDump aTPythonDump; // suppress dump in Reorient()
1025 SMESH::long_array_var anElementsId = theObject->GetIDs();
1026 CORBA::Boolean isDone = Reorient(anElementsId);
1028 // Update Python script
1029 aTPythonDump << "isDone = " << this << ".ReorientObject( " << theObject << " )";
1034 //=============================================================================
1038 //=============================================================================
1039 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
1040 SMESH::NumericalFunctor_ptr Criterion,
1041 CORBA::Double MaxAngle)
1045 SMESHDS_Mesh* aMesh = GetMeshDS();
1046 TIDSortedElemSet faces;
1047 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1049 SMESH::NumericalFunctor_i* aNumericalFunctor =
1050 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1051 SMESH::Controls::NumericalFunctorPtr aCrit;
1052 if ( !aNumericalFunctor )
1053 aCrit.reset( new SMESH::Controls::AspectRatio() );
1055 aCrit = aNumericalFunctor->GetNumericalFunctor();
1057 // Update Python script
1058 TPythonDump() << "isDone = " << this << ".TriToQuad( "
1059 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1061 ::SMESH_MeshEditor anEditor( myMesh );
1063 bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
1065 myMesh->SetIsModified( true ); // issue 0020693
1067 storeResult(anEditor);
1073 //=============================================================================
1077 //=============================================================================
1078 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1079 SMESH::NumericalFunctor_ptr Criterion,
1080 CORBA::Double MaxAngle)
1084 TPythonDump aTPythonDump; // suppress dump in TriToQuad()
1085 SMESH::long_array_var anElementsId = theObject->GetIDs();
1086 CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
1088 SMESH::NumericalFunctor_i* aNumericalFunctor =
1089 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1091 // Update Python script
1092 aTPythonDump << "isDone = " << this << ".TriToQuadObject("
1093 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
1099 //=============================================================================
1103 //=============================================================================
1104 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array & IDsOfElements,
1105 SMESH::NumericalFunctor_ptr Criterion)
1109 SMESHDS_Mesh* aMesh = GetMeshDS();
1110 TIDSortedElemSet faces;
1111 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1113 SMESH::NumericalFunctor_i* aNumericalFunctor =
1114 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
1115 SMESH::Controls::NumericalFunctorPtr aCrit;
1116 if ( !aNumericalFunctor )
1117 aCrit.reset( new SMESH::Controls::AspectRatio() );
1119 aCrit = aNumericalFunctor->GetNumericalFunctor();
1122 // Update Python script
1123 TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1125 ::SMESH_MeshEditor anEditor( myMesh );
1126 CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1128 myMesh->SetIsModified( true ); // issue 0020693
1130 storeResult(anEditor);
1136 //=============================================================================
1140 //=============================================================================
1141 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr theObject,
1142 SMESH::NumericalFunctor_ptr Criterion)
1146 TPythonDump aTPythonDump; // suppress dump in QuadToTri()
1148 SMESH::long_array_var anElementsId = theObject->GetIDs();
1149 CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1151 SMESH::NumericalFunctor_i* aNumericalFunctor =
1152 SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1154 // Update Python script
1155 aTPythonDump << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1161 //=============================================================================
1165 //=============================================================================
1166 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1167 CORBA::Boolean Diag13)
1171 SMESHDS_Mesh* aMesh = GetMeshDS();
1172 TIDSortedElemSet faces;
1173 arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1175 // Update Python script
1176 TPythonDump() << "isDone = " << this << ".SplitQuad( "
1177 << IDsOfElements << ", " << Diag13 << " )";
1179 ::SMESH_MeshEditor anEditor( myMesh );
1180 CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1182 myMesh->SetIsModified( true ); // issue 0020693
1185 storeResult(anEditor);
1191 //=============================================================================
1195 //=============================================================================
1196 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1197 CORBA::Boolean Diag13)
1201 TPythonDump aTPythonDump; // suppress dump in SplitQuad()
1203 SMESH::long_array_var anElementsId = theObject->GetIDs();
1204 CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1206 // Update Python script
1207 aTPythonDump << "isDone = " << this << ".SplitQuadObject( "
1208 << theObject << ", " << Diag13 << " )";
1214 //=============================================================================
1218 //=============================================================================
1219 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long IDOfQuad,
1220 SMESH::NumericalFunctor_ptr Criterion)
1224 const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1225 if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1227 SMESH::NumericalFunctor_i* aNumericalFunctor =
1228 dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1229 SMESH::Controls::NumericalFunctorPtr aCrit;
1230 if (aNumericalFunctor)
1231 aCrit = aNumericalFunctor->GetNumericalFunctor();
1233 aCrit.reset(new SMESH::Controls::AspectRatio());
1235 ::SMESH_MeshEditor anEditor (myMesh);
1236 return anEditor.BestSplit(quad, aCrit);
1241 //================================================================================
1243 * \brief Split volumic elements into tetrahedrons
1245 //================================================================================
1247 void SMESH_MeshEditor_i::SplitVolumesIntoTetra (SMESH::SMESH_IDSource_ptr elems,
1248 CORBA::Short methodFlags)
1249 throw (SALOME::SALOME_Exception)
1251 Unexpect aCatch(SALOME_SalomeException);
1255 SMESH::long_array_var anElementsId = elems->GetIDs();
1256 TIDSortedElemSet elemSet;
1257 arrayToSet( anElementsId, GetMeshDS(), elemSet, SMDSAbs_Volume );
1259 ::SMESH_MeshEditor anEditor (myMesh);
1260 anEditor.SplitVolumesIntoTetra( elemSet, int( methodFlags ));
1262 storeResult(anEditor);
1264 // if ( myLastCreatedElems.length() ) - it does not influence Compute()
1265 // myMesh->SetIsModified( true ); // issue 0020693
1267 TPythonDump() << this << ".SplitVolumesIntoTetra( "
1268 << elems << ", " << methodFlags << " )";
1271 //=======================================================================
1274 //=======================================================================
1277 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
1278 const SMESH::long_array & IDsOfFixedNodes,
1279 CORBA::Long MaxNbOfIterations,
1280 CORBA::Double MaxAspectRatio,
1281 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1283 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1284 MaxAspectRatio, Method, false );
1288 //=======================================================================
1289 //function : SmoothParametric
1291 //=======================================================================
1294 SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array & IDsOfElements,
1295 const SMESH::long_array & IDsOfFixedNodes,
1296 CORBA::Long MaxNbOfIterations,
1297 CORBA::Double MaxAspectRatio,
1298 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1300 return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1301 MaxAspectRatio, Method, true );
1305 //=======================================================================
1306 //function : SmoothObject
1308 //=======================================================================
1311 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
1312 const SMESH::long_array & IDsOfFixedNodes,
1313 CORBA::Long MaxNbOfIterations,
1314 CORBA::Double MaxAspectRatio,
1315 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1317 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1318 MaxAspectRatio, Method, false);
1322 //=======================================================================
1323 //function : SmoothParametricObject
1325 //=======================================================================
1328 SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr theObject,
1329 const SMESH::long_array & IDsOfFixedNodes,
1330 CORBA::Long MaxNbOfIterations,
1331 CORBA::Double MaxAspectRatio,
1332 SMESH::SMESH_MeshEditor::Smooth_Method Method)
1334 return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1335 MaxAspectRatio, Method, true);
1339 //=============================================================================
1343 //=============================================================================
1346 SMESH_MeshEditor_i::smooth(const SMESH::long_array & IDsOfElements,
1347 const SMESH::long_array & IDsOfFixedNodes,
1348 CORBA::Long MaxNbOfIterations,
1349 CORBA::Double MaxAspectRatio,
1350 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1355 SMESHDS_Mesh* aMesh = GetMeshDS();
1357 TIDSortedElemSet elements;
1358 arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1360 set<const SMDS_MeshNode*> fixedNodes;
1361 for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1362 CORBA::Long index = IDsOfFixedNodes[i];
1363 const SMDS_MeshNode * node = aMesh->FindNode(index);
1365 fixedNodes.insert( node );
1367 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1368 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1369 method = ::SMESH_MeshEditor::CENTROIDAL;
1371 ::SMESH_MeshEditor anEditor( myMesh );
1372 anEditor.Smooth(elements, fixedNodes, method,
1373 MaxNbOfIterations, MaxAspectRatio, IsParametric );
1375 myMesh->SetIsModified( true ); // issue 0020693
1377 storeResult(anEditor);
1379 // Update Python script
1380 TPythonDump() << "isDone = " << this << "."
1381 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1382 << IDsOfElements << ", " << IDsOfFixedNodes << ", "
1383 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1384 << "SMESH.SMESH_MeshEditor."
1385 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1386 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1392 //=============================================================================
1396 //=============================================================================
1399 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr theObject,
1400 const SMESH::long_array & IDsOfFixedNodes,
1401 CORBA::Long MaxNbOfIterations,
1402 CORBA::Double MaxAspectRatio,
1403 SMESH::SMESH_MeshEditor::Smooth_Method Method,
1408 TPythonDump aTPythonDump; // suppress dump in smooth()
1410 SMESH::long_array_var anElementsId = theObject->GetIDs();
1411 CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1412 MaxAspectRatio, Method, IsParametric);
1414 // Update Python script
1415 aTPythonDump << "isDone = " << this << "."
1416 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1417 << theObject << ", " << IDsOfFixedNodes << ", "
1418 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1419 << "SMESH.SMESH_MeshEditor."
1420 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1421 "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1427 //=============================================================================
1431 //=============================================================================
1433 void SMESH_MeshEditor_i::RenumberNodes()
1435 // Update Python script
1436 TPythonDump() << this << ".RenumberNodes()";
1438 GetMeshDS()->Renumber( true );
1442 //=============================================================================
1446 //=============================================================================
1448 void SMESH_MeshEditor_i::RenumberElements()
1450 // Update Python script
1451 TPythonDump() << this << ".RenumberElements()";
1453 GetMeshDS()->Renumber( false );
1456 //=======================================================================
1458 * \brief Return groups by their IDs
1460 //=======================================================================
1462 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1466 myMesh_i->CreateGroupServants();
1467 return myMesh_i->GetGroups( *groupIDs );
1470 //=======================================================================
1471 //function : rotationSweep
1473 //=======================================================================
1475 SMESH::ListOfGroups*
1476 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1477 const SMESH::AxisStruct & theAxis,
1478 CORBA::Double theAngleInRadians,
1479 CORBA::Long theNbOfSteps,
1480 CORBA::Double theTolerance,
1481 const bool theMakeGroups,
1482 const SMDSAbs_ElementType theElementType)
1486 TIDSortedElemSet inElements, copyElements;
1487 arrayToSet(theIDsOfElements, GetMeshDS(), inElements, theElementType);
1489 TIDSortedElemSet* workElements = & inElements;
1490 TPreviewMesh tmpMesh( SMDSAbs_Face );
1491 SMESH_Mesh* mesh = 0;
1492 bool makeWalls=true;
1493 if ( myPreviewMode )
1495 SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1496 tmpMesh.Copy( inElements, copyElements, select, avoid );
1498 workElements = & copyElements;
1499 //makeWalls = false;
1506 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
1507 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1509 ::SMESH_MeshEditor anEditor( mesh );
1510 ::SMESH_MeshEditor::PGroupIDs groupIds =
1511 anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1512 theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1513 storeResult(anEditor);
1515 // myMesh->SetIsModified( true ); -- it does not influence Compute()
1517 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1520 //=======================================================================
1521 //function : RotationSweep
1523 //=======================================================================
1525 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1526 const SMESH::AxisStruct & theAxis,
1527 CORBA::Double theAngleInRadians,
1528 CORBA::Long theNbOfSteps,
1529 CORBA::Double theTolerance)
1531 if ( !myPreviewMode ) {
1532 TPythonDump() << this << ".RotationSweep( "
1533 << theIDsOfElements << ", "
1535 << theAngleInRadians << ", "
1536 << theNbOfSteps << ", "
1537 << theTolerance << " )";
1539 rotationSweep(theIDsOfElements,
1547 //=======================================================================
1548 //function : RotationSweepMakeGroups
1550 //=======================================================================
1552 SMESH::ListOfGroups*
1553 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1554 const SMESH::AxisStruct& theAxis,
1555 CORBA::Double theAngleInRadians,
1556 CORBA::Long theNbOfSteps,
1557 CORBA::Double theTolerance)
1559 SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1565 if ( !myPreviewMode ) {
1566 TPythonDump aPythonDump;
1567 DumpGroupsList(aPythonDump,aGroups);
1568 aPythonDump<< this << ".RotationSweepMakeGroups( "
1569 << theIDsOfElements << ", "
1571 << theAngleInRadians << ", "
1572 << theNbOfSteps << ", "
1573 << theTolerance << " )";
1578 //=======================================================================
1579 //function : RotationSweepObject
1581 //=======================================================================
1583 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1584 const SMESH::AxisStruct & theAxis,
1585 CORBA::Double theAngleInRadians,
1586 CORBA::Long theNbOfSteps,
1587 CORBA::Double theTolerance)
1589 if ( !myPreviewMode ) {
1590 TPythonDump() << this << ".RotationSweepObject( "
1591 << theObject << ", "
1593 << theAngleInRadians << ", "
1594 << theNbOfSteps << ", "
1595 << theTolerance << " )";
1597 SMESH::long_array_var anElementsId = theObject->GetIDs();
1598 rotationSweep(anElementsId,
1606 //=======================================================================
1607 //function : RotationSweepObject1D
1609 //=======================================================================
1611 void SMESH_MeshEditor_i::RotationSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1612 const SMESH::AxisStruct & theAxis,
1613 CORBA::Double theAngleInRadians,
1614 CORBA::Long theNbOfSteps,
1615 CORBA::Double theTolerance)
1617 if ( !myPreviewMode ) {
1618 TPythonDump() << this << ".RotationSweepObject1D( "
1619 << theObject << ", "
1621 << theAngleInRadians << ", "
1622 << theNbOfSteps << ", "
1623 << theTolerance << " )";
1625 SMESH::long_array_var anElementsId = theObject->GetIDs();
1626 rotationSweep(anElementsId,
1635 //=======================================================================
1636 //function : RotationSweepObject2D
1638 //=======================================================================
1640 void SMESH_MeshEditor_i::RotationSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1641 const SMESH::AxisStruct & theAxis,
1642 CORBA::Double theAngleInRadians,
1643 CORBA::Long theNbOfSteps,
1644 CORBA::Double theTolerance)
1646 if ( !myPreviewMode ) {
1647 TPythonDump() << this << ".RotationSweepObject2D( "
1648 << theObject << ", "
1650 << theAngleInRadians << ", "
1651 << theNbOfSteps << ", "
1652 << theTolerance << " )";
1654 SMESH::long_array_var anElementsId = theObject->GetIDs();
1655 rotationSweep(anElementsId,
1664 //=======================================================================
1665 //function : RotationSweepObjectMakeGroups
1667 //=======================================================================
1669 SMESH::ListOfGroups*
1670 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1671 const SMESH::AxisStruct& theAxis,
1672 CORBA::Double theAngleInRadians,
1673 CORBA::Long theNbOfSteps,
1674 CORBA::Double theTolerance)
1676 SMESH::long_array_var anElementsId = theObject->GetIDs();
1677 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1683 if ( !myPreviewMode ) {
1684 TPythonDump aPythonDump;
1685 DumpGroupsList(aPythonDump,aGroups);
1686 aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1687 << theObject << ", "
1689 << theAngleInRadians << ", "
1690 << theNbOfSteps << ", "
1691 << theTolerance << " )";
1696 //=======================================================================
1697 //function : RotationSweepObject1DMakeGroups
1699 //=======================================================================
1701 SMESH::ListOfGroups*
1702 SMESH_MeshEditor_i::RotationSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1703 const SMESH::AxisStruct& theAxis,
1704 CORBA::Double theAngleInRadians,
1705 CORBA::Long theNbOfSteps,
1706 CORBA::Double theTolerance)
1708 SMESH::long_array_var anElementsId = theObject->GetIDs();
1709 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1716 if ( !myPreviewMode ) {
1717 TPythonDump aPythonDump;
1718 DumpGroupsList(aPythonDump,aGroups);
1719 aPythonDump<< this << ".RotationSweepObject1DMakeGroups( "
1720 << theObject << ", "
1722 << theAngleInRadians << ", "
1723 << theNbOfSteps << ", "
1724 << theTolerance << " )";
1729 //=======================================================================
1730 //function : RotationSweepObject2DMakeGroups
1732 //=======================================================================
1734 SMESH::ListOfGroups*
1735 SMESH_MeshEditor_i::RotationSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1736 const SMESH::AxisStruct& theAxis,
1737 CORBA::Double theAngleInRadians,
1738 CORBA::Long theNbOfSteps,
1739 CORBA::Double theTolerance)
1741 SMESH::long_array_var anElementsId = theObject->GetIDs();
1742 SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1749 if ( !myPreviewMode ) {
1750 TPythonDump aPythonDump;
1751 DumpGroupsList(aPythonDump,aGroups);
1752 aPythonDump<< this << ".RotationSweepObject2DMakeGroups( "
1753 << theObject << ", "
1755 << theAngleInRadians << ", "
1756 << theNbOfSteps << ", "
1757 << theTolerance << " )";
1763 //=======================================================================
1764 //function : extrusionSweep
1766 //=======================================================================
1768 SMESH::ListOfGroups*
1769 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1770 const SMESH::DirStruct & theStepVector,
1771 CORBA::Long theNbOfSteps,
1772 const bool theMakeGroups,
1773 const SMDSAbs_ElementType theElementType)
1781 TIDSortedElemSet elements;
1782 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1784 const SMESH::PointStruct * P = &theStepVector.PS;
1785 gp_Vec stepVec( P->x, P->y, P->z );
1787 TElemOfElemListMap aHystory;
1788 ::SMESH_MeshEditor anEditor( myMesh );
1789 ::SMESH_MeshEditor::PGroupIDs groupIds =
1790 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1792 storeResult(anEditor);
1794 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1796 } catch(Standard_Failure) {
1797 Handle(Standard_Failure) aFail = Standard_Failure::Caught();
1798 INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1803 //=======================================================================
1804 //function : ExtrusionSweep
1806 //=======================================================================
1808 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1809 const SMESH::DirStruct & theStepVector,
1810 CORBA::Long theNbOfSteps)
1812 extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1813 if ( !myPreviewMode ) {
1814 TPythonDump() << this << ".ExtrusionSweep( "
1815 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1820 //=======================================================================
1821 //function : ExtrusionSweepObject
1823 //=======================================================================
1825 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1826 const SMESH::DirStruct & theStepVector,
1827 CORBA::Long theNbOfSteps)
1829 SMESH::long_array_var anElementsId = theObject->GetIDs();
1830 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1831 if ( !myPreviewMode ) {
1832 TPythonDump() << this << ".ExtrusionSweepObject( "
1833 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1837 //=======================================================================
1838 //function : ExtrusionSweepObject1D
1840 //=======================================================================
1842 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1843 const SMESH::DirStruct & theStepVector,
1844 CORBA::Long theNbOfSteps)
1846 SMESH::long_array_var anElementsId = theObject->GetIDs();
1847 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1848 if ( !myPreviewMode ) {
1849 TPythonDump() << this << ".ExtrusionSweepObject1D( "
1850 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1854 //=======================================================================
1855 //function : ExtrusionSweepObject2D
1857 //=======================================================================
1859 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1860 const SMESH::DirStruct & theStepVector,
1861 CORBA::Long theNbOfSteps)
1863 SMESH::long_array_var anElementsId = theObject->GetIDs();
1864 extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1865 if ( !myPreviewMode ) {
1866 TPythonDump() << this << ".ExtrusionSweepObject2D( "
1867 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1871 //=======================================================================
1872 //function : ExtrusionSweepMakeGroups
1874 //=======================================================================
1876 SMESH::ListOfGroups*
1877 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1878 const SMESH::DirStruct& theStepVector,
1879 CORBA::Long theNbOfSteps)
1881 SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1883 if ( !myPreviewMode ) {
1884 TPythonDump aPythonDump;
1885 DumpGroupsList(aPythonDump,aGroups);
1886 aPythonDump << this << ".ExtrusionSweepMakeGroups( "
1887 << theIDsOfElements << ", " << theStepVector <<", " << theNbOfSteps << " )";
1891 //=======================================================================
1892 //function : ExtrusionSweepObjectMakeGroups
1894 //=======================================================================
1896 SMESH::ListOfGroups*
1897 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1898 const SMESH::DirStruct& theStepVector,
1899 CORBA::Long theNbOfSteps)
1901 SMESH::long_array_var anElementsId = theObject->GetIDs();
1902 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1904 if ( !myPreviewMode ) {
1905 TPythonDump aPythonDump;
1906 DumpGroupsList(aPythonDump,aGroups);
1907 aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1908 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1913 //=======================================================================
1914 //function : ExtrusionSweepObject1DMakeGroups
1916 //=======================================================================
1918 SMESH::ListOfGroups*
1919 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1920 const SMESH::DirStruct& theStepVector,
1921 CORBA::Long theNbOfSteps)
1923 SMESH::long_array_var anElementsId = theObject->GetIDs();
1924 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1925 if ( !myPreviewMode ) {
1926 TPythonDump aPythonDump;
1927 DumpGroupsList(aPythonDump,aGroups);
1928 aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1929 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1934 //=======================================================================
1935 //function : ExtrusionSweepObject2DMakeGroups
1937 //=======================================================================
1939 SMESH::ListOfGroups*
1940 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1941 const SMESH::DirStruct& theStepVector,
1942 CORBA::Long theNbOfSteps)
1944 SMESH::long_array_var anElementsId = theObject->GetIDs();
1945 SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1946 if ( !myPreviewMode ) {
1947 TPythonDump aPythonDump;
1948 DumpGroupsList(aPythonDump,aGroups);
1949 aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1950 << theObject << ", " << theStepVector << ", " << theNbOfSteps << " )";
1956 //=======================================================================
1957 //function : advancedExtrusion
1959 //=======================================================================
1961 SMESH::ListOfGroups*
1962 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1963 const SMESH::DirStruct & theStepVector,
1964 CORBA::Long theNbOfSteps,
1965 CORBA::Long theExtrFlags,
1966 CORBA::Double theSewTolerance,
1967 const bool theMakeGroups)
1971 TIDSortedElemSet elements;
1972 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1974 const SMESH::PointStruct * P = &theStepVector.PS;
1975 gp_Vec stepVec( P->x, P->y, P->z );
1977 ::SMESH_MeshEditor anEditor( myMesh );
1978 TElemOfElemListMap aHystory;
1979 ::SMESH_MeshEditor::PGroupIDs groupIds =
1980 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1981 theMakeGroups, theExtrFlags, theSewTolerance);
1982 storeResult(anEditor);
1984 return theMakeGroups ? getGroups(groupIds.get()) : 0;
1987 //=======================================================================
1988 //function : AdvancedExtrusion
1990 //=======================================================================
1992 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1993 const SMESH::DirStruct & theStepVector,
1994 CORBA::Long theNbOfSteps,
1995 CORBA::Long theExtrFlags,
1996 CORBA::Double theSewTolerance)
1998 if ( !myPreviewMode ) {
1999 TPythonDump() << "stepVector = " << theStepVector;
2000 TPythonDump() << this << ".AdvancedExtrusion("
2003 << theNbOfSteps << ","
2004 << theExtrFlags << ", "
2005 << theSewTolerance << " )";
2007 advancedExtrusion( theIDsOfElements,
2015 //=======================================================================
2016 //function : AdvancedExtrusionMakeGroups
2018 //=======================================================================
2020 SMESH::ListOfGroups*
2021 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
2022 const SMESH::DirStruct& theStepVector,
2023 CORBA::Long theNbOfSteps,
2024 CORBA::Long theExtrFlags,
2025 CORBA::Double theSewTolerance)
2027 SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
2034 if ( !myPreviewMode ) {
2035 TPythonDump() << "stepVector = " << theStepVector;
2036 TPythonDump aPythonDump;
2037 DumpGroupsList(aPythonDump,aGroups);
2038 aPythonDump << this << ".AdvancedExtrusionMakeGroups("
2041 << theNbOfSteps << ","
2042 << theExtrFlags << ", "
2043 << theSewTolerance << " )";
2049 //================================================================================
2051 * \brief Convert extrusion error to IDL enum
2053 //================================================================================
2055 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
2057 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
2061 RETCASE( EXTR_NO_ELEMENTS );
2062 RETCASE( EXTR_PATH_NOT_EDGE );
2063 RETCASE( EXTR_BAD_PATH_SHAPE );
2064 RETCASE( EXTR_BAD_STARTING_NODE );
2065 RETCASE( EXTR_BAD_ANGLES_NUMBER );
2066 RETCASE( EXTR_CANT_GET_TANGENT );
2068 return SMESH::SMESH_MeshEditor::EXTR_OK;
2072 //=======================================================================
2073 //function : extrusionAlongPath
2075 //=======================================================================
2077 SMESH::ListOfGroups*
2078 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2079 SMESH::SMESH_Mesh_ptr thePathMesh,
2080 GEOM::GEOM_Object_ptr thePathShape,
2081 CORBA::Long theNodeStart,
2082 CORBA::Boolean theHasAngles,
2083 const SMESH::double_array & theAngles,
2084 CORBA::Boolean theHasRefPoint,
2085 const SMESH::PointStruct & theRefPoint,
2086 const bool theMakeGroups,
2087 SMESH::SMESH_MeshEditor::Extrusion_Error & theError,
2088 const SMDSAbs_ElementType theElementType)
2092 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
2093 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2096 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2098 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2099 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2101 if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
2102 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2106 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
2108 theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2112 TIDSortedElemSet elements;
2113 arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
2115 list<double> angles;
2116 for (int i = 0; i < theAngles.length(); i++) {
2117 angles.push_back( theAngles[i] );
2120 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
2122 int nbOldGroups = myMesh->NbGroup();
2124 ::SMESH_MeshEditor anEditor( myMesh );
2125 ::SMESH_MeshEditor::Extrusion_Error error =
2126 anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
2127 theHasAngles, angles, false,
2128 theHasRefPoint, refPnt, theMakeGroups );
2129 storeResult(anEditor);
2130 theError = convExtrError( error );
2132 if ( theMakeGroups ) {
2133 list<int> groupIDs = myMesh->GetGroupIds();
2134 list<int>::iterator newBegin = groupIDs.begin();
2135 std::advance( newBegin, nbOldGroups ); // skip old groups
2136 groupIDs.erase( groupIDs.begin(), newBegin );
2137 return getGroups( & groupIDs );
2143 //=======================================================================
2144 //function : extrusionAlongPathX
2146 //=======================================================================
2148 SMESH::ListOfGroups*
2149 SMESH_MeshEditor_i::extrusionAlongPathX(const SMESH::long_array & IDsOfElements,
2150 SMESH::SMESH_IDSource_ptr Path,
2151 CORBA::Long NodeStart,
2152 CORBA::Boolean HasAngles,
2153 const SMESH::double_array& Angles,
2154 CORBA::Boolean LinearVariation,
2155 CORBA::Boolean HasRefPoint,
2156 const SMESH::PointStruct& RefPoint,
2157 const bool MakeGroups,
2158 const SMDSAbs_ElementType ElementType,
2159 SMESH::SMESH_MeshEditor::Extrusion_Error & Error)
2161 SMESH::ListOfGroups* EmptyGr = new SMESH::ListOfGroups;
2165 list<double> angles;
2166 for (int i = 0; i < Angles.length(); i++) {
2167 angles.push_back( Angles[i] );
2169 gp_Pnt refPnt( RefPoint.x, RefPoint.y, RefPoint.z );
2170 int nbOldGroups = myMesh->NbGroup();
2172 if ( Path->_is_nil() ) {
2173 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2177 TIDSortedElemSet elements;
2178 arrayToSet(IDsOfElements, GetMeshDS(), elements, ElementType);
2180 ::SMESH_MeshEditor anEditor( myMesh );
2181 ::SMESH_MeshEditor::Extrusion_Error error;
2183 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( Path );
2186 SMDS_MeshNode* aNodeStart =
2187 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2188 if ( !aNodeStart ) {
2189 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2192 error = anEditor.ExtrusionAlongTrack( elements, &(aMeshImp->GetImpl()), aNodeStart,
2193 HasAngles, angles, LinearVariation,
2194 HasRefPoint, refPnt, MakeGroups );
2197 SMESH_subMesh_i* aSubMeshImp = SMESH::DownCast<SMESH_subMesh_i*>( Path );
2200 SMESH::SMESH_Mesh_ptr aPathMesh = aSubMeshImp->GetFather();
2201 aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( aPathMesh );
2202 SMDS_MeshNode* aNodeStart =
2203 (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(NodeStart);
2204 if ( !aNodeStart ) {
2205 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
2208 SMESH_subMesh* aSubMesh =
2209 aMeshImp->GetImpl().GetSubMeshContaining(aSubMeshImp->GetId());
2210 error = anEditor.ExtrusionAlongTrack( elements, aSubMesh, aNodeStart,
2211 HasAngles, angles, LinearVariation,
2212 HasRefPoint, refPnt, MakeGroups );
2215 SMESH_Group_i* aGroupImp = SMESH::DownCast<SMESH_Group_i*>( Path );
2217 // path as group of 1D elements
2221 Error = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
2227 storeResult(anEditor);
2228 Error = convExtrError( error );
2231 list<int> groupIDs = myMesh->GetGroupIds();
2232 list<int>::iterator newBegin = groupIDs.begin();
2233 std::advance( newBegin, nbOldGroups ); // skip old groups
2234 groupIDs.erase( groupIDs.begin(), newBegin );
2235 return getGroups( & groupIDs );
2241 //=======================================================================
2242 //function : ExtrusionAlongPath
2244 //=======================================================================
2246 SMESH::SMESH_MeshEditor::Extrusion_Error
2247 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
2248 SMESH::SMESH_Mesh_ptr thePathMesh,
2249 GEOM::GEOM_Object_ptr thePathShape,
2250 CORBA::Long theNodeStart,
2251 CORBA::Boolean theHasAngles,
2252 const SMESH::double_array & theAngles,
2253 CORBA::Boolean theHasRefPoint,
2254 const SMESH::PointStruct & theRefPoint)
2256 if ( !myPreviewMode ) {
2257 TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
2258 << theIDsOfElements << ", "
2259 << thePathMesh << ", "
2260 << thePathShape << ", "
2261 << theNodeStart << ", "
2262 << theHasAngles << ", "
2263 << theAngles << ", "
2264 << theHasRefPoint << ", "
2265 << "SMESH.PointStruct( "
2266 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2267 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2268 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2270 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2271 extrusionAlongPath( theIDsOfElements,
2284 //=======================================================================
2285 //function : ExtrusionAlongPathObject
2287 //=======================================================================
2289 SMESH::SMESH_MeshEditor::Extrusion_Error
2290 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
2291 SMESH::SMESH_Mesh_ptr thePathMesh,
2292 GEOM::GEOM_Object_ptr thePathShape,
2293 CORBA::Long theNodeStart,
2294 CORBA::Boolean theHasAngles,
2295 const SMESH::double_array & theAngles,
2296 CORBA::Boolean theHasRefPoint,
2297 const SMESH::PointStruct & theRefPoint)
2299 if ( !myPreviewMode ) {
2300 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
2301 << theObject << ", "
2302 << thePathMesh << ", "
2303 << thePathShape << ", "
2304 << theNodeStart << ", "
2305 << theHasAngles << ", "
2306 << theAngles << ", "
2307 << theHasRefPoint << ", "
2308 << "SMESH.PointStruct( "
2309 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2310 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2311 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2313 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2314 SMESH::long_array_var anElementsId = theObject->GetIDs();
2315 extrusionAlongPath( anElementsId,
2328 //=======================================================================
2329 //function : ExtrusionAlongPathObject1D
2331 //=======================================================================
2333 SMESH::SMESH_MeshEditor::Extrusion_Error
2334 SMESH_MeshEditor_i::ExtrusionAlongPathObject1D(SMESH::SMESH_IDSource_ptr theObject,
2335 SMESH::SMESH_Mesh_ptr thePathMesh,
2336 GEOM::GEOM_Object_ptr thePathShape,
2337 CORBA::Long theNodeStart,
2338 CORBA::Boolean theHasAngles,
2339 const SMESH::double_array & theAngles,
2340 CORBA::Boolean theHasRefPoint,
2341 const SMESH::PointStruct & theRefPoint)
2343 if ( !myPreviewMode ) {
2344 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject1D( "
2345 << theObject << ", "
2346 << thePathMesh << ", "
2347 << thePathShape << ", "
2348 << theNodeStart << ", "
2349 << theHasAngles << ", "
2350 << theAngles << ", "
2351 << theHasRefPoint << ", "
2352 << "SMESH.PointStruct( "
2353 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2354 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2355 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2357 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2358 SMESH::long_array_var anElementsId = theObject->GetIDs();
2359 extrusionAlongPath( anElementsId,
2373 //=======================================================================
2374 //function : ExtrusionAlongPathObject2D
2376 //=======================================================================
2378 SMESH::SMESH_MeshEditor::Extrusion_Error
2379 SMESH_MeshEditor_i::ExtrusionAlongPathObject2D(SMESH::SMESH_IDSource_ptr theObject,
2380 SMESH::SMESH_Mesh_ptr thePathMesh,
2381 GEOM::GEOM_Object_ptr thePathShape,
2382 CORBA::Long theNodeStart,
2383 CORBA::Boolean theHasAngles,
2384 const SMESH::double_array & theAngles,
2385 CORBA::Boolean theHasRefPoint,
2386 const SMESH::PointStruct & theRefPoint)
2388 if ( !myPreviewMode ) {
2389 TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject2D( "
2390 << theObject << ", "
2391 << thePathMesh << ", "
2392 << thePathShape << ", "
2393 << theNodeStart << ", "
2394 << theHasAngles << ", "
2395 << theAngles << ", "
2396 << theHasRefPoint << ", "
2397 << "SMESH.PointStruct( "
2398 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2399 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2400 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2402 SMESH::SMESH_MeshEditor::Extrusion_Error anError;
2403 SMESH::long_array_var anElementsId = theObject->GetIDs();
2404 extrusionAlongPath( anElementsId,
2419 //=======================================================================
2420 //function : ExtrusionAlongPathMakeGroups
2422 //=======================================================================
2424 SMESH::ListOfGroups*
2425 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array& theIDsOfElements,
2426 SMESH::SMESH_Mesh_ptr thePathMesh,
2427 GEOM::GEOM_Object_ptr thePathShape,
2428 CORBA::Long theNodeStart,
2429 CORBA::Boolean theHasAngles,
2430 const SMESH::double_array& theAngles,
2431 CORBA::Boolean theHasRefPoint,
2432 const SMESH::PointStruct& theRefPoint,
2433 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2435 SMESH::ListOfGroups * aGroups = extrusionAlongPath( theIDsOfElements,
2445 if ( !myPreviewMode ) {
2446 bool isDumpGroups = aGroups && aGroups->length() > 0;
2447 TPythonDump aPythonDump;
2449 aPythonDump << "("<<aGroups;
2452 aPythonDump << ", error)";
2454 aPythonDump <<"error";
2456 aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2457 << theIDsOfElements << ", "
2458 << thePathMesh << ", "
2459 << thePathShape << ", "
2460 << theNodeStart << ", "
2461 << theHasAngles << ", "
2462 << theAngles << ", "
2463 << theHasRefPoint << ", "
2464 << "SMESH.PointStruct( "
2465 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2466 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2467 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2472 //=======================================================================
2473 //function : ExtrusionAlongPathObjectMakeGroups
2475 //=======================================================================
2477 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2478 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2479 SMESH::SMESH_Mesh_ptr thePathMesh,
2480 GEOM::GEOM_Object_ptr thePathShape,
2481 CORBA::Long theNodeStart,
2482 CORBA::Boolean theHasAngles,
2483 const SMESH::double_array& theAngles,
2484 CORBA::Boolean theHasRefPoint,
2485 const SMESH::PointStruct& theRefPoint,
2486 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2488 SMESH::long_array_var anElementsId = theObject->GetIDs();
2489 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2500 if ( !myPreviewMode ) {
2501 bool isDumpGroups = aGroups && aGroups->length() > 0;
2502 TPythonDump aPythonDump;
2504 aPythonDump << "("<<aGroups;
2507 aPythonDump << ", error)";
2509 aPythonDump <<"error";
2511 aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2512 << theObject << ", "
2513 << thePathMesh << ", "
2514 << thePathShape << ", "
2515 << theNodeStart << ", "
2516 << theHasAngles << ", "
2517 << theAngles << ", "
2518 << theHasRefPoint << ", "
2519 << "SMESH.PointStruct( "
2520 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2521 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2522 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2527 //=======================================================================
2528 //function : ExtrusionAlongPathObject1DMakeGroups
2530 //=======================================================================
2532 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2533 ExtrusionAlongPathObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2534 SMESH::SMESH_Mesh_ptr thePathMesh,
2535 GEOM::GEOM_Object_ptr thePathShape,
2536 CORBA::Long theNodeStart,
2537 CORBA::Boolean theHasAngles,
2538 const SMESH::double_array& theAngles,
2539 CORBA::Boolean theHasRefPoint,
2540 const SMESH::PointStruct& theRefPoint,
2541 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2543 SMESH::long_array_var anElementsId = theObject->GetIDs();
2544 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2556 if ( !myPreviewMode ) {
2557 bool isDumpGroups = aGroups && aGroups->length() > 0;
2558 TPythonDump aPythonDump;
2560 aPythonDump << "("<<aGroups;
2563 aPythonDump << ", error)";
2565 aPythonDump <<"error";
2567 aPythonDump << " = " << this << ".ExtrusionAlongPathObject1DMakeGroups( "
2568 << theObject << ", "
2569 << thePathMesh << ", "
2570 << thePathShape << ", "
2571 << theNodeStart << ", "
2572 << theHasAngles << ", "
2573 << theAngles << ", "
2574 << theHasRefPoint << ", "
2575 << "SMESH.PointStruct( "
2576 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2577 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2578 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2583 //=======================================================================
2584 //function : ExtrusionAlongPathObject2DMakeGroups
2586 //=======================================================================
2588 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2589 ExtrusionAlongPathObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2590 SMESH::SMESH_Mesh_ptr thePathMesh,
2591 GEOM::GEOM_Object_ptr thePathShape,
2592 CORBA::Long theNodeStart,
2593 CORBA::Boolean theHasAngles,
2594 const SMESH::double_array& theAngles,
2595 CORBA::Boolean theHasRefPoint,
2596 const SMESH::PointStruct& theRefPoint,
2597 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2599 SMESH::long_array_var anElementsId = theObject->GetIDs();
2600 SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2612 if ( !myPreviewMode ) {
2613 bool isDumpGroups = aGroups && aGroups->length() > 0;
2614 TPythonDump aPythonDump;
2616 aPythonDump << "("<<aGroups;
2619 aPythonDump << ", error)";
2621 aPythonDump <<"error";
2623 aPythonDump << " = " << this << ".ExtrusionAlongPathObject2DMakeGroups( "
2624 << theObject << ", "
2625 << thePathMesh << ", "
2626 << thePathShape << ", "
2627 << theNodeStart << ", "
2628 << theHasAngles << ", "
2629 << theAngles << ", "
2630 << theHasRefPoint << ", "
2631 << "SMESH.PointStruct( "
2632 << ( theHasRefPoint ? theRefPoint.x : 0 ) << ", "
2633 << ( theHasRefPoint ? theRefPoint.y : 0 ) << ", "
2634 << ( theHasRefPoint ? theRefPoint.z : 0 ) << " ) )";
2640 //=======================================================================
2641 //function : ExtrusionAlongPathObjX
2643 //=======================================================================
2644 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2645 ExtrusionAlongPathObjX(SMESH::SMESH_IDSource_ptr Object,
2646 SMESH::SMESH_IDSource_ptr Path,
2647 CORBA::Long NodeStart,
2648 CORBA::Boolean HasAngles,
2649 const SMESH::double_array& Angles,
2650 CORBA::Boolean LinearVariation,
2651 CORBA::Boolean HasRefPoint,
2652 const SMESH::PointStruct& RefPoint,
2653 CORBA::Boolean MakeGroups,
2654 SMESH::ElementType ElemType,
2655 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2657 SMESH::long_array_var anElementsId = Object->GetIDs();
2658 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(anElementsId,
2667 (SMDSAbs_ElementType)ElemType,
2670 if ( !myPreviewMode ) {
2671 bool isDumpGroups = aGroups && aGroups->length() > 0;
2672 TPythonDump aPythonDump;
2674 aPythonDump << "("<<aGroups;
2677 aPythonDump << ", error)";
2679 aPythonDump <<"error";
2681 aPythonDump << " = " << this << ".ExtrusionAlongPathObjX( "
2684 << NodeStart << ", "
2685 << HasAngles << ", "
2687 << LinearVariation << ", "
2688 << HasRefPoint << ", "
2689 << "SMESH.PointStruct( "
2690 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2691 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2692 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2693 << MakeGroups << ", "
2694 << ElemType << " )";
2700 //=======================================================================
2701 //function : ExtrusionAlongPathX
2703 //=======================================================================
2704 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2705 ExtrusionAlongPathX(const SMESH::long_array& IDsOfElements,
2706 SMESH::SMESH_IDSource_ptr Path,
2707 CORBA::Long NodeStart,
2708 CORBA::Boolean HasAngles,
2709 const SMESH::double_array& Angles,
2710 CORBA::Boolean LinearVariation,
2711 CORBA::Boolean HasRefPoint,
2712 const SMESH::PointStruct& RefPoint,
2713 CORBA::Boolean MakeGroups,
2714 SMESH::ElementType ElemType,
2715 SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2717 SMESH::ListOfGroups * aGroups = extrusionAlongPathX(IDsOfElements,
2726 (SMDSAbs_ElementType)ElemType,
2729 if ( !myPreviewMode ) {
2730 bool isDumpGroups = aGroups && aGroups->length() > 0;
2731 TPythonDump aPythonDump;
2733 aPythonDump << "("<<aGroups;
2736 aPythonDump << ", error)";
2738 aPythonDump <<"error";
2740 aPythonDump << " = " << this << ".ExtrusionAlongPathX( "
2741 << IDsOfElements << ", "
2743 << NodeStart << ", "
2744 << HasAngles << ", "
2746 << LinearVariation << ", "
2747 << HasRefPoint << ", "
2748 << "SMESH.PointStruct( "
2749 << ( HasRefPoint ? RefPoint.x : 0 ) << ", "
2750 << ( HasRefPoint ? RefPoint.y : 0 ) << ", "
2751 << ( HasRefPoint ? RefPoint.z : 0 ) << " ), "
2752 << ElemType << " )";
2758 //================================================================================
2760 * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2761 * of given angles along path steps
2762 * \param PathMesh mesh containing a 1D sub-mesh on the edge, along
2763 * which proceeds the extrusion
2764 * \param PathShape is shape(edge); as the mesh can be complex, the edge
2765 * is used to define the sub-mesh for the path
2767 //================================================================================
2769 SMESH::double_array*
2770 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr thePathMesh,
2771 GEOM::GEOM_Object_ptr thePathShape,
2772 const SMESH::double_array & theAngles)
2774 SMESH::double_array_var aResult = new SMESH::double_array();
2775 int nbAngles = theAngles.length();
2776 if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2778 SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2779 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2780 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2781 if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2782 return aResult._retn();
2783 int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2784 if ( nbSteps == nbAngles )
2786 aResult.inout() = theAngles;
2790 aResult->length( nbSteps );
2791 double rAn2St = double( nbAngles ) / double( nbSteps );
2792 double angPrev = 0, angle;
2793 for ( int iSt = 0; iSt < nbSteps; ++iSt )
2795 double angCur = rAn2St * ( iSt+1 );
2796 double angCurFloor = floor( angCur );
2797 double angPrevFloor = floor( angPrev );
2798 if ( angPrevFloor == angCurFloor )
2799 angle = rAn2St * theAngles[ int( angCurFloor ) ];
2802 int iP = int( angPrevFloor );
2803 double angPrevCeil = ceil(angPrev);
2804 angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2806 int iC = int( angCurFloor );
2807 if ( iC < nbAngles )
2808 angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2810 iP = int( angPrevCeil );
2812 angle += theAngles[ iC ];
2814 aResult[ iSt ] = angle;
2819 // Update Python script
2820 TPythonDump() << "rotAngles = " << theAngles;
2821 TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2822 << thePathMesh << ", "
2823 << thePathShape << ", "
2826 return aResult._retn();
2830 //=======================================================================
2833 //=======================================================================
2835 SMESH::ListOfGroups*
2836 SMESH_MeshEditor_i::mirror(TIDSortedElemSet & theElements,
2837 const SMESH::AxisStruct & theAxis,
2838 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2839 CORBA::Boolean theCopy,
2840 const bool theMakeGroups,
2841 ::SMESH_Mesh* theTargetMesh)
2845 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2846 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2849 switch ( theMirrorType ) {
2850 case SMESH::SMESH_MeshEditor::POINT:
2851 aTrsf.SetMirror( P );
2853 case SMESH::SMESH_MeshEditor::AXIS:
2854 aTrsf.SetMirror( gp_Ax1( P, V ));
2857 aTrsf.SetMirror( gp_Ax2( P, V ));
2860 ::SMESH_MeshEditor anEditor( myMesh );
2861 ::SMESH_MeshEditor::PGroupIDs groupIds =
2862 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2865 storeResult(anEditor);
2867 myMesh->SetIsModified( true );
2869 return theMakeGroups ? getGroups(groupIds.get()) : 0;
2872 //=======================================================================
2875 //=======================================================================
2877 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
2878 const SMESH::AxisStruct & theAxis,
2879 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2880 CORBA::Boolean theCopy)
2882 if ( !myPreviewMode ) {
2883 TPythonDump() << this << ".Mirror( "
2884 << theIDsOfElements << ", "
2886 << mirrorTypeName(theMirrorType) << ", "
2889 if ( theIDsOfElements.length() > 0 )
2891 TIDSortedElemSet elements;
2892 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2893 mirror(elements, theAxis, theMirrorType, theCopy, false);
2898 //=======================================================================
2899 //function : MirrorObject
2901 //=======================================================================
2903 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
2904 const SMESH::AxisStruct & theAxis,
2905 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2906 CORBA::Boolean theCopy)
2908 if ( !myPreviewMode ) {
2909 TPythonDump() << this << ".MirrorObject( "
2910 << theObject << ", "
2912 << mirrorTypeName(theMirrorType) << ", "
2915 TIDSortedElemSet elements;
2916 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2917 mirror(elements, theAxis, theMirrorType, theCopy, false);
2920 //=======================================================================
2921 //function : MirrorMakeGroups
2923 //=======================================================================
2925 SMESH::ListOfGroups*
2926 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array& theIDsOfElements,
2927 const SMESH::AxisStruct& theMirror,
2928 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2930 SMESH::ListOfGroups * aGroups = 0;
2931 if ( theIDsOfElements.length() > 0 )
2933 TIDSortedElemSet elements;
2934 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2935 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2937 if ( !myPreviewMode ) {
2938 TPythonDump aPythonDump;
2939 DumpGroupsList(aPythonDump,aGroups);
2940 aPythonDump << this << ".MirrorMakeGroups( "
2941 << theIDsOfElements << ", "
2942 << theMirror << ", "
2943 << mirrorTypeName(theMirrorType) << " )";
2948 //=======================================================================
2949 //function : MirrorObjectMakeGroups
2951 //=======================================================================
2953 SMESH::ListOfGroups*
2954 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2955 const SMESH::AxisStruct& theMirror,
2956 SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2958 SMESH::ListOfGroups * aGroups = 0;
2959 TIDSortedElemSet elements;
2960 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
2961 aGroups = mirror(elements, theMirror, theMirrorType, true, true);
2963 if ( !myPreviewMode )
2965 TPythonDump aPythonDump;
2966 DumpGroupsList(aPythonDump,aGroups);
2967 aPythonDump << this << ".MirrorObjectMakeGroups( "
2968 << theObject << ", "
2969 << theMirror << ", "
2970 << mirrorTypeName(theMirrorType) << " )";
2975 //=======================================================================
2976 //function : MirrorMakeMesh
2978 //=======================================================================
2980 SMESH::SMESH_Mesh_ptr
2981 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array& theIDsOfElements,
2982 const SMESH::AxisStruct& theMirror,
2983 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2984 CORBA::Boolean theCopyGroups,
2985 const char* theMeshName)
2987 SMESH_Mesh_i* mesh_i;
2988 SMESH::SMESH_Mesh_var mesh;
2989 { // open new scope to dump "MakeMesh" command
2990 // and then "GetGroups" using SMESH_Mesh::GetGroups()
2992 TPythonDump pydump; // to prevent dump at mesh creation
2994 mesh = makeMesh( theMeshName );
2995 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2996 if (mesh_i && theIDsOfElements.length() > 0 )
2998 TIDSortedElemSet elements;
2999 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3000 mirror(elements, theMirror, theMirrorType,
3001 false, theCopyGroups, & mesh_i->GetImpl());
3002 mesh_i->CreateGroupServants();
3005 if ( !myPreviewMode ) {
3006 pydump << mesh << " = " << this << ".MirrorMakeMesh( "
3007 << theIDsOfElements << ", "
3008 << theMirror << ", "
3009 << mirrorTypeName(theMirrorType) << ", "
3010 << theCopyGroups << ", '"
3011 << theMeshName << "' )";
3016 if(!myPreviewMode && mesh_i)
3017 mesh_i->GetGroups();
3019 return mesh._retn();
3022 //=======================================================================
3023 //function : MirrorObjectMakeMesh
3025 //=======================================================================
3027 SMESH::SMESH_Mesh_ptr
3028 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3029 const SMESH::AxisStruct& theMirror,
3030 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
3031 CORBA::Boolean theCopyGroups,
3032 const char* theMeshName)
3034 SMESH_Mesh_i* mesh_i;
3035 SMESH::SMESH_Mesh_var mesh;
3036 { // open new scope to dump "MakeMesh" command
3037 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3039 TPythonDump pydump; // to prevent dump at mesh creation
3041 mesh = makeMesh( theMeshName );
3042 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3043 TIDSortedElemSet elements;
3045 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3047 mirror(elements, theMirror, theMirrorType,
3048 false, theCopyGroups, & mesh_i->GetImpl());
3049 mesh_i->CreateGroupServants();
3051 if ( !myPreviewMode ) {
3052 pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
3053 << theObject << ", "
3054 << theMirror << ", "
3055 << mirrorTypeName(theMirrorType) << ", "
3056 << theCopyGroups << ", '"
3057 << theMeshName << "' )";
3062 if(!myPreviewMode && mesh_i)
3063 mesh_i->GetGroups();
3065 return mesh._retn();
3068 //=======================================================================
3069 //function : translate
3071 //=======================================================================
3073 SMESH::ListOfGroups*
3074 SMESH_MeshEditor_i::translate(TIDSortedElemSet & theElements,
3075 const SMESH::DirStruct & theVector,
3076 CORBA::Boolean theCopy,
3077 const bool theMakeGroups,
3078 ::SMESH_Mesh* theTargetMesh)
3083 const SMESH::PointStruct * P = &theVector.PS;
3084 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
3086 ::SMESH_MeshEditor anEditor( myMesh );
3087 ::SMESH_MeshEditor::PGroupIDs groupIds =
3088 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3091 storeResult(anEditor);
3093 myMesh->SetIsModified( true );
3095 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3098 //=======================================================================
3099 //function : Translate
3101 //=======================================================================
3103 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
3104 const SMESH::DirStruct & theVector,
3105 CORBA::Boolean theCopy)
3107 if ( !myPreviewMode ) {
3108 TPythonDump() << this << ".Translate( "
3109 << theIDsOfElements << ", "
3110 << theVector << ", "
3113 if ( theIDsOfElements.length() )
3115 TIDSortedElemSet elements;
3116 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3117 translate(elements,theVector,theCopy,false);
3121 //=======================================================================
3122 //function : TranslateObject
3124 //=======================================================================
3126 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
3127 const SMESH::DirStruct & theVector,
3128 CORBA::Boolean theCopy)
3130 if ( !myPreviewMode ) {
3131 TPythonDump() << this << ".TranslateObject( "
3132 << theObject << ", "
3133 << theVector << ", "
3136 TIDSortedElemSet elements;
3137 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3138 translate( elements, theVector, theCopy, false);
3141 //=======================================================================
3142 //function : TranslateMakeGroups
3144 //=======================================================================
3146 SMESH::ListOfGroups*
3147 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
3148 const SMESH::DirStruct& theVector)
3150 SMESH::ListOfGroups * aGroups = 0;
3151 if ( theIDsOfElements.length() )
3153 TIDSortedElemSet elements;
3154 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3155 aGroups = translate(elements,theVector,true,true);
3157 if ( !myPreviewMode ) {
3158 TPythonDump aPythonDump;
3159 DumpGroupsList(aPythonDump,aGroups);
3160 aPythonDump << this << ".TranslateMakeGroups( "
3161 << theIDsOfElements << ", "
3162 << theVector << " )";
3167 //=======================================================================
3168 //function : TranslateObjectMakeGroups
3170 //=======================================================================
3172 SMESH::ListOfGroups*
3173 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3174 const SMESH::DirStruct& theVector)
3176 SMESH::ListOfGroups * aGroups = 0;
3177 TIDSortedElemSet elements;
3178 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3179 aGroups = translate(elements, theVector, true, true);
3181 if ( !myPreviewMode ) {
3183 TPythonDump aPythonDump;
3184 DumpGroupsList(aPythonDump,aGroups);
3185 aPythonDump << this << ".TranslateObjectMakeGroups( "
3186 << theObject << ", "
3187 << theVector << " )";
3192 //=======================================================================
3193 //function : TranslateMakeMesh
3195 //=======================================================================
3197 SMESH::SMESH_Mesh_ptr
3198 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
3199 const SMESH::DirStruct& theVector,
3200 CORBA::Boolean theCopyGroups,
3201 const char* theMeshName)
3203 SMESH_Mesh_i* mesh_i;
3204 SMESH::SMESH_Mesh_var mesh;
3206 { // open new scope to dump "MakeMesh" command
3207 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3209 TPythonDump pydump; // to prevent dump at mesh creation
3211 mesh = makeMesh( theMeshName );
3212 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3214 if ( mesh_i && theIDsOfElements.length() )
3216 TIDSortedElemSet elements;
3217 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3218 translate(elements, theVector, false, theCopyGroups, & mesh_i->GetImpl());
3219 mesh_i->CreateGroupServants();
3222 if ( !myPreviewMode ) {
3223 pydump << mesh << " = " << this << ".TranslateMakeMesh( "
3224 << theIDsOfElements << ", "
3225 << theVector << ", "
3226 << theCopyGroups << ", '"
3227 << theMeshName << "' )";
3232 if(!myPreviewMode && mesh_i)
3233 mesh_i->GetGroups();
3235 return mesh._retn();
3238 //=======================================================================
3239 //function : TranslateObjectMakeMesh
3241 //=======================================================================
3243 SMESH::SMESH_Mesh_ptr
3244 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3245 const SMESH::DirStruct& theVector,
3246 CORBA::Boolean theCopyGroups,
3247 const char* theMeshName)
3249 SMESH_Mesh_i* mesh_i;
3250 SMESH::SMESH_Mesh_var mesh;
3251 { // open new scope to dump "MakeMesh" command
3252 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3254 TPythonDump pydump; // to prevent dump at mesh creation
3255 mesh = makeMesh( theMeshName );
3256 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3258 TIDSortedElemSet elements;
3260 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3262 translate(elements, theVector,false, theCopyGroups, & mesh_i->GetImpl());
3263 mesh_i->CreateGroupServants();
3265 if ( !myPreviewMode ) {
3266 pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
3267 << theObject << ", "
3268 << theVector << ", "
3269 << theCopyGroups << ", '"
3270 << theMeshName << "' )";
3275 if(!myPreviewMode && mesh_i)
3276 mesh_i->GetGroups();
3278 return mesh._retn();
3281 //=======================================================================
3284 //=======================================================================
3286 SMESH::ListOfGroups*
3287 SMESH_MeshEditor_i::rotate(TIDSortedElemSet & theElements,
3288 const SMESH::AxisStruct & theAxis,
3289 CORBA::Double theAngle,
3290 CORBA::Boolean theCopy,
3291 const bool theMakeGroups,
3292 ::SMESH_Mesh* theTargetMesh)
3296 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
3297 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
3300 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
3302 ::SMESH_MeshEditor anEditor( myMesh );
3303 ::SMESH_MeshEditor::PGroupIDs groupIds =
3304 anEditor.Transform (theElements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3307 storeResult(anEditor);
3309 myMesh->SetIsModified( true );
3311 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3314 //=======================================================================
3317 //=======================================================================
3319 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
3320 const SMESH::AxisStruct & theAxis,
3321 CORBA::Double theAngle,
3322 CORBA::Boolean theCopy)
3324 if ( !myPreviewMode ) {
3325 TPythonDump() << this << ".Rotate( "
3326 << theIDsOfElements << ", "
3331 if ( theIDsOfElements.length() > 0 )
3333 TIDSortedElemSet elements;
3334 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3335 rotate(elements,theAxis,theAngle,theCopy,false);
3339 //=======================================================================
3340 //function : RotateObject
3342 //=======================================================================
3344 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
3345 const SMESH::AxisStruct & theAxis,
3346 CORBA::Double theAngle,
3347 CORBA::Boolean theCopy)
3349 if ( !myPreviewMode ) {
3350 TPythonDump() << this << ".RotateObject( "
3351 << theObject << ", "
3356 TIDSortedElemSet elements;
3357 if (idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3358 rotate(elements,theAxis,theAngle,theCopy,false);
3361 //=======================================================================
3362 //function : RotateMakeGroups
3364 //=======================================================================
3366 SMESH::ListOfGroups*
3367 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
3368 const SMESH::AxisStruct& theAxis,
3369 CORBA::Double theAngle)
3371 SMESH::ListOfGroups * aGroups = 0;
3372 if ( theIDsOfElements.length() > 0 )
3374 TIDSortedElemSet elements;
3375 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3376 aGroups = rotate(elements,theAxis,theAngle,true,true);
3378 if ( !myPreviewMode ) {
3379 TPythonDump aPythonDump;
3380 DumpGroupsList(aPythonDump,aGroups);
3381 aPythonDump << this << ".RotateMakeGroups( "
3382 << theIDsOfElements << ", "
3384 << theAngle << " )";
3389 //=======================================================================
3390 //function : RotateObjectMakeGroups
3392 //=======================================================================
3394 SMESH::ListOfGroups*
3395 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3396 const SMESH::AxisStruct& theAxis,
3397 CORBA::Double theAngle)
3399 SMESH::ListOfGroups * aGroups = 0;
3400 TIDSortedElemSet elements;
3401 if ( idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3402 aGroups = rotate(elements,theAxis,theAngle,true,true);
3404 if ( !myPreviewMode ) {
3405 TPythonDump aPythonDump;
3406 DumpGroupsList(aPythonDump,aGroups);
3407 aPythonDump << this << ".RotateObjectMakeGroups( "
3408 << theObject << ", "
3410 << theAngle << " )";
3415 //=======================================================================
3416 //function : RotateMakeMesh
3418 //=======================================================================
3420 SMESH::SMESH_Mesh_ptr
3421 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
3422 const SMESH::AxisStruct& theAxis,
3423 CORBA::Double theAngleInRadians,
3424 CORBA::Boolean theCopyGroups,
3425 const char* theMeshName)
3427 SMESH::SMESH_Mesh_var mesh;
3428 SMESH_Mesh_i* mesh_i;
3430 { // open new scope to dump "MakeMesh" command
3431 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3433 TPythonDump pydump; // to prevent dump at mesh creation
3435 mesh = makeMesh( theMeshName );
3436 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3438 if ( mesh_i && theIDsOfElements.length() > 0 )
3440 TIDSortedElemSet elements;
3441 arrayToSet(theIDsOfElements, GetMeshDS(), elements);
3442 rotate(elements, theAxis, theAngleInRadians,
3443 false, theCopyGroups, & mesh_i->GetImpl());
3444 mesh_i->CreateGroupServants();
3446 if ( !myPreviewMode ) {
3447 pydump << mesh << " = " << this << ".RotateMakeMesh( "
3448 << theIDsOfElements << ", "
3450 << theAngleInRadians << ", "
3451 << theCopyGroups << ", '"
3452 << theMeshName << "' )";
3457 if(!myPreviewMode && mesh_i && theIDsOfElements.length() > 0 )
3458 mesh_i->GetGroups();
3460 return mesh._retn();
3463 //=======================================================================
3464 //function : RotateObjectMakeMesh
3466 //=======================================================================
3468 SMESH::SMESH_Mesh_ptr
3469 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3470 const SMESH::AxisStruct& theAxis,
3471 CORBA::Double theAngleInRadians,
3472 CORBA::Boolean theCopyGroups,
3473 const char* theMeshName)
3475 SMESH::SMESH_Mesh_var mesh;
3476 SMESH_Mesh_i* mesh_i;
3478 {// open new scope to dump "MakeMesh" command
3479 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3481 TPythonDump pydump; // to prevent dump at mesh creation
3482 mesh = makeMesh( theMeshName );
3483 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3485 TIDSortedElemSet elements;
3487 idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1))
3489 rotate(elements, theAxis, theAngleInRadians,
3490 false, theCopyGroups, & mesh_i->GetImpl());
3491 mesh_i->CreateGroupServants();
3493 if ( !myPreviewMode ) {
3494 pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
3495 << theObject << ", "
3497 << theAngleInRadians << ", "
3498 << theCopyGroups << ", '"
3499 << theMeshName << "' )";
3504 if(!myPreviewMode && mesh_i)
3505 mesh_i->GetGroups();
3507 return mesh._retn();
3510 //=======================================================================
3513 //=======================================================================
3515 SMESH::ListOfGroups*
3516 SMESH_MeshEditor_i::scale(SMESH::SMESH_IDSource_ptr theObject,
3517 const SMESH::PointStruct& thePoint,
3518 const SMESH::double_array& theScaleFact,
3519 CORBA::Boolean theCopy,
3520 const bool theMakeGroups,
3521 ::SMESH_Mesh* theTargetMesh)
3524 if ( theScaleFact.length() < 1 )
3525 THROW_SALOME_CORBA_EXCEPTION("Scale factor not given", SALOME::BAD_PARAM);
3526 if ( theScaleFact.length() == 2 )
3527 THROW_SALOME_CORBA_EXCEPTION("Invalid nb of scale factors : 2", SALOME::BAD_PARAM);
3529 TIDSortedElemSet elements;
3530 if ( !idSourceToSet(theObject, GetMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/true))
3533 vector<double> S(3);
3534 S[0] = theScaleFact[0];
3535 S[1] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[1];
3536 S[2] = (theScaleFact.length() == 1) ? theScaleFact[0] : theScaleFact[2];
3537 double tol = std::numeric_limits<double>::max();
3539 aTrsf.SetValues( S[0], 0, 0, thePoint.x * (1-S[0]),
3540 0, S[1], 0, thePoint.y * (1-S[1]),
3541 0, 0, S[2], thePoint.z * (1-S[2]), tol, tol);
3543 ::SMESH_MeshEditor anEditor( myMesh );
3544 ::SMESH_MeshEditor::PGroupIDs groupIds =
3545 anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
3548 storeResult(anEditor);
3550 myMesh->SetIsModified( true );
3552 return theMakeGroups ? getGroups(groupIds.get()) : 0;
3555 //=======================================================================
3558 //=======================================================================
3560 void SMESH_MeshEditor_i::Scale(SMESH::SMESH_IDSource_ptr theObject,
3561 const SMESH::PointStruct& thePoint,
3562 const SMESH::double_array& theScaleFact,
3563 CORBA::Boolean theCopy)
3565 if ( !myPreviewMode ) {
3566 TPythonDump() << this << ".Scale( "
3567 << theObject << ", "
3568 << "SMESH.PointStruct( " << thePoint.x << ", "
3569 << thePoint.y << ", " << thePoint.z << " ) ,"
3570 << theScaleFact << ", "
3573 scale(theObject, thePoint, theScaleFact, theCopy, false);
3577 //=======================================================================
3578 //function : ScaleMakeGroups
3580 //=======================================================================
3582 SMESH::ListOfGroups*
3583 SMESH_MeshEditor_i::ScaleMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
3584 const SMESH::PointStruct& thePoint,
3585 const SMESH::double_array& theScaleFact)
3587 SMESH::ListOfGroups * aGroups = scale(theObject, thePoint, theScaleFact, true, true);
3588 if ( !myPreviewMode ) {
3590 TPythonDump aPythonDump;
3591 DumpGroupsList(aPythonDump,aGroups);
3592 aPythonDump << this << ".Scale("
3594 << "SMESH.PointStruct(" <<thePoint.x << ","
3595 << thePoint.y << "," << thePoint.z << "),"
3596 << theScaleFact << ",True,True)";
3602 //=======================================================================
3603 //function : ScaleMakeMesh
3605 //=======================================================================
3607 SMESH::SMESH_Mesh_ptr
3608 SMESH_MeshEditor_i::ScaleMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
3609 const SMESH::PointStruct& thePoint,
3610 const SMESH::double_array& theScaleFact,
3611 CORBA::Boolean theCopyGroups,
3612 const char* theMeshName)
3614 SMESH_Mesh_i* mesh_i;
3615 SMESH::SMESH_Mesh_var mesh;
3616 { // open new scope to dump "MakeMesh" command
3617 // and then "GetGroups" using SMESH_Mesh::GetGroups()
3619 TPythonDump pydump; // to prevent dump at mesh creation
3620 mesh = makeMesh( theMeshName );
3621 mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
3625 scale(theObject, thePoint, theScaleFact,false, theCopyGroups, & mesh_i->GetImpl());
3626 mesh_i->CreateGroupServants();
3628 if ( !myPreviewMode )
3629 pydump << mesh << " = " << this << ".ScaleMakeMesh( "
3630 << theObject << ", "
3631 << "SMESH.PointStruct( " << thePoint.x << ", "
3632 << thePoint.y << ", " << thePoint.z << " ) ,"
3633 << theScaleFact << ", "
3634 << theCopyGroups << ", '"
3635 << theMeshName << "' )";
3639 if(!myPreviewMode && mesh_i)
3640 mesh_i->GetGroups();
3642 return mesh._retn();
3646 //=======================================================================
3647 //function : FindCoincidentNodes
3649 //=======================================================================
3651 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
3652 SMESH::array_of_long_array_out GroupsOfNodes)
3656 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3657 ::SMESH_MeshEditor anEditor( myMesh );
3658 TIDSortedNodeSet nodes; // no input nodes
3659 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3661 GroupsOfNodes = new SMESH::array_of_long_array;
3662 GroupsOfNodes->length( aListOfListOfNodes.size() );
3663 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3664 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
3665 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3666 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3667 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3668 aGroup.length( aListOfNodes.size() );
3669 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3670 aGroup[ j ] = (*lIt)->GetID();
3672 TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
3673 << Tolerance << " )";
3676 //=======================================================================
3677 //function : FindCoincidentNodesOnPart
3679 //=======================================================================
3680 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr theObject,
3681 CORBA::Double Tolerance,
3682 SMESH::array_of_long_array_out GroupsOfNodes)
3686 TIDSortedNodeSet nodes;
3687 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3689 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3690 ::SMESH_MeshEditor anEditor( myMesh );
3692 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
3694 GroupsOfNodes = new SMESH::array_of_long_array;
3695 GroupsOfNodes->length( aListOfListOfNodes.size() );
3696 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3697 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3699 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3700 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3701 SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
3702 aGroup.length( aListOfNodes.size() );
3703 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3704 aGroup[ j ] = (*lIt)->GetID();
3706 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
3708 << Tolerance << " )";
3711 //================================================================================
3713 * \brief Finds nodes coinsident with Tolerance within Object excluding nodes within
3714 * ExceptSubMeshOrGroups
3716 //================================================================================
3718 void SMESH_MeshEditor_i::
3719 FindCoincidentNodesOnPartBut(SMESH::SMESH_IDSource_ptr theObject,
3720 CORBA::Double theTolerance,
3721 SMESH::array_of_long_array_out theGroupsOfNodes,
3722 const SMESH::ListOfIDSources& theExceptSubMeshOrGroups)
3726 TIDSortedNodeSet nodes;
3727 idSourceToNodeSet( theObject, GetMeshDS(), nodes );
3729 for ( int i = 0; i < theExceptSubMeshOrGroups.length(); ++i )
3731 TIDSortedNodeSet exceptNodes;
3732 idSourceToNodeSet( theExceptSubMeshOrGroups[i], GetMeshDS(), exceptNodes );
3733 TIDSortedNodeSet::iterator avoidNode = exceptNodes.begin();
3734 for ( ; avoidNode != exceptNodes.end(); ++avoidNode)
3735 nodes.erase( *avoidNode );
3737 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3738 ::SMESH_MeshEditor anEditor( myMesh );
3740 anEditor.FindCoincidentNodes( nodes, theTolerance, aListOfListOfNodes );
3742 theGroupsOfNodes = new SMESH::array_of_long_array;
3743 theGroupsOfNodes->length( aListOfListOfNodes.size() );
3744 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
3745 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
3747 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
3748 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
3749 SMESH::long_array& aGroup = (*theGroupsOfNodes)[ i ];
3750 aGroup.length( aListOfNodes.size() );
3751 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
3752 aGroup[ j ] = (*lIt)->GetID();
3754 TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPartBut( "
3756 << theTolerance << ", "
3757 << theExceptSubMeshOrGroups << " )";
3760 //=======================================================================
3761 //function : MergeNodes
3763 //=======================================================================
3765 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
3769 SMESHDS_Mesh* aMesh = GetMeshDS();
3771 TPythonDump aTPythonDump;
3772 aTPythonDump << this << ".MergeNodes([";
3773 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
3774 for (int i = 0; i < GroupsOfNodes.length(); i++)
3776 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
3777 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
3778 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
3779 for ( int j = 0; j < aNodeGroup.length(); j++ )
3781 CORBA::Long index = aNodeGroup[ j ];
3782 const SMDS_MeshNode * node = aMesh->FindNode(index);
3784 aListOfNodes.push_back( node );
3786 if ( aListOfNodes.size() < 2 )
3787 aListOfListOfNodes.pop_back();
3789 if ( i > 0 ) aTPythonDump << ", ";
3790 aTPythonDump << aNodeGroup;
3792 ::SMESH_MeshEditor anEditor( myMesh );
3793 anEditor.MergeNodes( aListOfListOfNodes );
3795 aTPythonDump << "])";
3797 myMesh->SetIsModified( true );
3800 //=======================================================================
3801 //function : FindEqualElements
3803 //=======================================================================
3804 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr theObject,
3805 SMESH::array_of_long_array_out GroupsOfElementsID)
3809 SMESH::SMESH_GroupBase_var group = SMESH::SMESH_GroupBase::_narrow(theObject);
3810 if ( !(!group->_is_nil() && group->GetType() == SMESH::NODE) )
3812 typedef list<int> TListOfIDs;
3813 set<const SMDS_MeshElement*> elems;
3814 SMESH::long_array_var aElementsId = theObject->GetIDs();
3815 SMESHDS_Mesh* aMesh = GetMeshDS();
3817 for(int i = 0; i < aElementsId->length(); i++) {
3818 CORBA::Long anID = aElementsId[i];
3819 const SMDS_MeshElement * elem = aMesh->FindElement(anID);
3825 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3826 ::SMESH_MeshEditor anEditor( myMesh );
3827 anEditor.FindEqualElements( elems, aListOfListOfElementsID );
3829 GroupsOfElementsID = new SMESH::array_of_long_array;
3830 GroupsOfElementsID->length( aListOfListOfElementsID.size() );
3832 ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
3833 for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
3834 SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3835 TListOfIDs& listOfIDs = *arraysIt;
3836 aGroup.length( listOfIDs.size() );
3837 TListOfIDs::iterator idIt = listOfIDs.begin();
3838 for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3839 aGroup[ k ] = *idIt;
3843 TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3848 //=======================================================================
3849 //function : MergeElements
3851 //=======================================================================
3853 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3857 TPythonDump aTPythonDump;
3858 aTPythonDump << this << ".MergeElements( [";
3860 ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3862 for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3863 const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3864 aListOfListOfElementsID.push_back( list< int >() );
3865 list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3866 for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3867 CORBA::Long id = anElemsIDGroup[ j ];
3868 aListOfElemsID.push_back( id );
3870 if ( aListOfElemsID.size() < 2 )
3871 aListOfListOfElementsID.pop_back();
3872 if ( i > 0 ) aTPythonDump << ", ";
3873 aTPythonDump << anElemsIDGroup;
3876 ::SMESH_MeshEditor anEditor( myMesh );
3877 anEditor.MergeElements(aListOfListOfElementsID);
3879 myMesh->SetIsModified( true );
3881 aTPythonDump << "] )";
3884 //=======================================================================
3885 //function : MergeEqualElements
3887 //=======================================================================
3889 void SMESH_MeshEditor_i::MergeEqualElements()
3893 ::SMESH_MeshEditor anEditor( myMesh );
3894 anEditor.MergeEqualElements();
3896 TPythonDump() << this << ".MergeEqualElements()";
3899 //=============================================================================
3901 * Move the node to a given point
3903 //=============================================================================
3905 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
3910 initData(/*deleteSearchers=*/false);
3912 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
3916 if ( theNodeSearcher )
3917 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3919 if ( myPreviewMode ) // make preview data
3921 // in a preview mesh, make edges linked to a node
3922 TPreviewMesh tmpMesh;
3923 TIDSortedElemSet linkedNodes;
3924 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3925 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3926 for ( ; nIt != linkedNodes.end(); ++nIt )
3928 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3929 tmpMesh.Copy( &edge );
3932 node = tmpMesh.GetMeshDS()->FindNode( NodeID );
3934 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3935 // fill preview data
3936 ::SMESH_MeshEditor anEditor( & tmpMesh );
3937 storeResult( anEditor );
3939 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
3940 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
3942 GetMeshDS()->MoveNode(node, x, y, z);
3944 if ( !myPreviewMode )
3946 // Update Python script
3947 TPythonDump() << "isDone = " << this << ".MoveNode( "
3948 << NodeID << ", " << x << ", " << y << ", " << z << " )";
3950 myMesh->SetIsModified( true );
3956 //================================================================================
3958 * \brief Return ID of node closest to a given point
3960 //================================================================================
3962 CORBA::Long SMESH_MeshEditor_i::FindNodeClosestTo(CORBA::Double x,
3966 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3968 if ( !theNodeSearcher ) {
3969 ::SMESH_MeshEditor anEditor( myMesh );
3970 theNodeSearcher = anEditor.GetNodeSearcher();
3973 if ( const SMDS_MeshNode* node = theNodeSearcher->FindClosestTo( p ))
3974 return node->GetID();
3979 //================================================================================
3981 * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3982 * move the node closest to the point to point's location and return ID of the node
3984 //================================================================================
3986 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3989 CORBA::Long theNodeID)
3991 // We keep theNodeSearcher until any mesh modification:
3992 // 1) initData() deletes theNodeSearcher at any edition,
3993 // 2) TSearchersDeleter - at any mesh compute event and mesh change
3995 initData(/*deleteSearchers=*/false);
3997 theSearchersDeleter.Set( myMesh ); // remove theNodeSearcher if mesh is other
3999 int nodeID = theNodeID;
4000 const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
4001 if ( !node ) // preview moving node
4003 if ( !theNodeSearcher ) {
4004 ::SMESH_MeshEditor anEditor( myMesh );
4005 theNodeSearcher = anEditor.GetNodeSearcher();
4008 node = theNodeSearcher->FindClosestTo( p );
4011 nodeID = node->GetID();
4012 if ( myPreviewMode ) // make preview data
4014 // in a preview mesh, make edges linked to a node
4015 TPreviewMesh tmpMesh;
4016 TIDSortedElemSet linkedNodes;
4017 ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
4018 TIDSortedElemSet::iterator nIt = linkedNodes.begin();
4019 for ( ; nIt != linkedNodes.end(); ++nIt )
4021 SMDS_MeshEdge edge( node, cast2Node( *nIt ));
4022 tmpMesh.Copy( &edge );
4025 node = tmpMesh.GetMeshDS()->FindNode( nodeID );
4027 tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
4028 // fill preview data
4029 ::SMESH_MeshEditor anEditor( & tmpMesh );
4030 storeResult( anEditor );
4032 else if ( theNodeSearcher ) // move node and update theNodeSearcher data accordingly
4034 theNodeSearcher->MoveNode(node, gp_Pnt( x,y,z ));
4038 GetMeshDS()->MoveNode(node, x, y, z);
4042 if ( !myPreviewMode )
4044 TPythonDump() << "nodeID = " << this
4045 << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
4046 << ", " << nodeID << " )";
4048 myMesh->SetIsModified( true );
4054 //=======================================================================
4056 * Return elements of given type where the given point is IN or ON.
4058 * 'ALL' type means elements of any type excluding nodes
4060 //=======================================================================
4062 SMESH::long_array* SMESH_MeshEditor_i::FindElementsByPoint(CORBA::Double x,
4065 SMESH::ElementType type)
4067 SMESH::long_array_var res = new SMESH::long_array;
4068 vector< const SMDS_MeshElement* > foundElems;
4070 theSearchersDeleter.Set( myMesh );
4071 if ( !theElementSearcher ) {
4072 ::SMESH_MeshEditor anEditor( myMesh );
4073 theElementSearcher = anEditor.GetElementSearcher();
4075 theElementSearcher->FindElementsByPoint( gp_Pnt( x,y,z ),
4076 SMDSAbs_ElementType( type ),
4078 res->length( foundElems.size() );
4079 for ( int i = 0; i < foundElems.size(); ++i )
4080 res[i] = foundElems[i]->GetID();
4082 if ( !myPreviewMode ) // call from tui
4083 TPythonDump() << res << " = " << this << ".FindElementsByPoint( "
4092 //=======================================================================
4093 //function : GetPointState
4094 //purpose : Return point state in a closed 2D mesh in terms of TopAbs_State enumeration.
4095 // TopAbs_UNKNOWN state means that either mesh is wrong or the analysis fails.
4096 //=======================================================================
4098 CORBA::Short SMESH_MeshEditor_i::GetPointState(CORBA::Double x,
4102 theSearchersDeleter.Set( myMesh );
4103 if ( !theElementSearcher ) {
4104 ::SMESH_MeshEditor anEditor( myMesh );
4105 theElementSearcher = anEditor.GetElementSearcher();
4107 return CORBA::Short( theElementSearcher->GetPointState( gp_Pnt( x,y,z )));
4110 //=======================================================================
4111 //function : convError
4113 //=======================================================================
4115 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
4117 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
4121 RETCASE( SEW_BORDER1_NOT_FOUND );
4122 RETCASE( SEW_BORDER2_NOT_FOUND );
4123 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
4124 RETCASE( SEW_BAD_SIDE_NODES );
4125 RETCASE( SEW_VOLUMES_TO_SPLIT );
4126 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
4127 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
4128 RETCASE( SEW_BAD_SIDE1_NODES );
4129 RETCASE( SEW_BAD_SIDE2_NODES );
4131 return SMESH::SMESH_MeshEditor::SEW_OK;
4134 //=======================================================================
4135 //function : SewFreeBorders
4137 //=======================================================================
4139 SMESH::SMESH_MeshEditor::Sew_Error
4140 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
4141 CORBA::Long SecondNodeID1,
4142 CORBA::Long LastNodeID1,
4143 CORBA::Long FirstNodeID2,
4144 CORBA::Long SecondNodeID2,
4145 CORBA::Long LastNodeID2,
4146 CORBA::Boolean CreatePolygons,
4147 CORBA::Boolean CreatePolyedrs)
4151 SMESHDS_Mesh* aMesh = GetMeshDS();
4153 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4154 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4155 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4156 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4157 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4158 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
4160 if (!aBorderFirstNode ||
4161 !aBorderSecondNode||
4163 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4164 if (!aSide2FirstNode ||
4165 !aSide2SecondNode ||
4167 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4169 TPythonDump() << "error = " << this << ".SewFreeBorders( "
4170 << FirstNodeID1 << ", "
4171 << SecondNodeID1 << ", "
4172 << LastNodeID1 << ", "
4173 << FirstNodeID2 << ", "
4174 << SecondNodeID2 << ", "
4175 << LastNodeID2 << ", "
4176 << CreatePolygons<< ", "
4177 << CreatePolyedrs<< " )";
4179 ::SMESH_MeshEditor anEditor( myMesh );
4180 SMESH::SMESH_MeshEditor::Sew_Error error =
4181 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4191 storeResult(anEditor);
4193 myMesh->SetIsModified( true );
4199 //=======================================================================
4200 //function : SewConformFreeBorders
4202 //=======================================================================
4204 SMESH::SMESH_MeshEditor::Sew_Error
4205 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
4206 CORBA::Long SecondNodeID1,
4207 CORBA::Long LastNodeID1,
4208 CORBA::Long FirstNodeID2,
4209 CORBA::Long SecondNodeID2)
4213 SMESHDS_Mesh* aMesh = GetMeshDS();
4215 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
4216 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
4217 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
4218 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
4219 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
4220 const SMDS_MeshNode* aSide2ThirdNode = 0;
4222 if (!aBorderFirstNode ||
4223 !aBorderSecondNode||
4225 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4226 if (!aSide2FirstNode ||
4228 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
4230 TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
4231 << FirstNodeID1 << ", "
4232 << SecondNodeID1 << ", "
4233 << LastNodeID1 << ", "
4234 << FirstNodeID2 << ", "
4235 << SecondNodeID2 << " )";
4237 ::SMESH_MeshEditor anEditor( myMesh );
4238 SMESH::SMESH_MeshEditor::Sew_Error error =
4239 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4248 storeResult(anEditor);
4250 myMesh->SetIsModified( true );
4256 //=======================================================================
4257 //function : SewBorderToSide
4259 //=======================================================================
4261 SMESH::SMESH_MeshEditor::Sew_Error
4262 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
4263 CORBA::Long SecondNodeIDOnFreeBorder,
4264 CORBA::Long LastNodeIDOnFreeBorder,
4265 CORBA::Long FirstNodeIDOnSide,
4266 CORBA::Long LastNodeIDOnSide,
4267 CORBA::Boolean CreatePolygons,
4268 CORBA::Boolean CreatePolyedrs)
4272 SMESHDS_Mesh* aMesh = GetMeshDS();
4274 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
4275 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
4276 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
4277 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
4278 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
4279 const SMDS_MeshNode* aSide2ThirdNode = 0;
4281 if (!aBorderFirstNode ||
4282 !aBorderSecondNode||
4284 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
4285 if (!aSide2FirstNode ||
4287 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
4289 TPythonDump() << "error = " << this << ".SewBorderToSide( "
4290 << FirstNodeIDOnFreeBorder << ", "
4291 << SecondNodeIDOnFreeBorder << ", "
4292 << LastNodeIDOnFreeBorder << ", "
4293 << FirstNodeIDOnSide << ", "
4294 << LastNodeIDOnSide << ", "
4295 << CreatePolygons << ", "
4296 << CreatePolyedrs << ") ";
4298 ::SMESH_MeshEditor anEditor( myMesh );
4299 SMESH::SMESH_MeshEditor::Sew_Error error =
4300 convError( anEditor.SewFreeBorder (aBorderFirstNode,
4310 storeResult(anEditor);
4312 myMesh->SetIsModified( true );
4318 //=======================================================================
4319 //function : SewSideElements
4321 //=======================================================================
4323 SMESH::SMESH_MeshEditor::Sew_Error
4324 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
4325 const SMESH::long_array& IDsOfSide2Elements,
4326 CORBA::Long NodeID1OfSide1ToMerge,
4327 CORBA::Long NodeID1OfSide2ToMerge,
4328 CORBA::Long NodeID2OfSide1ToMerge,
4329 CORBA::Long NodeID2OfSide2ToMerge)
4333 SMESHDS_Mesh* aMesh = GetMeshDS();
4335 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
4336 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
4337 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
4338 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
4340 if (!aFirstNode1ToMerge ||
4341 !aFirstNode2ToMerge )
4342 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
4343 if (!aSecondNode1ToMerge||
4344 !aSecondNode2ToMerge)
4345 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
4347 TIDSortedElemSet aSide1Elems, aSide2Elems;
4348 arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
4349 arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
4351 TPythonDump() << "error = " << this << ".SewSideElements( "
4352 << IDsOfSide1Elements << ", "
4353 << IDsOfSide2Elements << ", "
4354 << NodeID1OfSide1ToMerge << ", "
4355 << NodeID1OfSide2ToMerge << ", "
4356 << NodeID2OfSide1ToMerge << ", "
4357 << NodeID2OfSide2ToMerge << ")";
4359 ::SMESH_MeshEditor anEditor( myMesh );
4360 SMESH::SMESH_MeshEditor::Sew_Error error =
4361 convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
4364 aSecondNode1ToMerge,
4365 aSecondNode2ToMerge));
4367 storeResult(anEditor);
4369 myMesh->SetIsModified( true );
4374 //================================================================================
4376 * \brief Set new nodes for given element
4377 * \param ide - element id
4378 * \param newIDs - new node ids
4379 * \retval CORBA::Boolean - true if result is OK
4381 //================================================================================
4383 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
4384 const SMESH::long_array& newIDs)
4388 const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
4389 if(!elem) return false;
4391 int nbn = newIDs.length();
4393 vector<const SMDS_MeshNode*> aNodes(nbn);
4396 const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
4399 aNodes[nbn1] = aNode;
4402 TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
4403 << ide << ", " << newIDs << " )";
4405 bool res = GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
4408 myMesh->SetIsModified( true );
4413 //================================================================================
4415 * \brief Update myLastCreated* or myPreviewData
4416 * \param anEditor - it contains last modification results
4418 //================================================================================
4420 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
4422 if ( myPreviewMode ) { // --- MeshPreviewStruct filling ---
4424 list<int> aNodesConnectivity;
4425 typedef map<int, int> TNodesMap;
4428 TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
4429 SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
4431 SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
4432 int nbEdges = aMeshDS->NbEdges();
4433 int nbFaces = aMeshDS->NbFaces();
4434 int nbVolum = aMeshDS->NbVolumes();
4435 switch ( previewType ) {
4436 case SMDSAbs_Edge : nbFaces = nbVolum = 0; break;
4437 case SMDSAbs_Face : nbEdges = nbVolum = 0; break;
4438 case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
4441 myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
4442 myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
4444 SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
4446 while ( itMeshElems->more() ) {
4447 const SMDS_MeshElement* aMeshElem = itMeshElems->next();
4448 if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
4451 SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
4452 while ( itElemNodes->more() ) {
4453 const SMDS_MeshNode* aMeshNode =
4454 static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
4455 int aNodeID = aMeshNode->GetID();
4456 TNodesMap::iterator anIter = nodesMap.find(aNodeID);
4457 if ( anIter == nodesMap.end() ) {
4458 // filling the nodes coordinates
4459 myPreviewData->nodesXYZ[j].x = aMeshNode->X();
4460 myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
4461 myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
4462 anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
4465 aNodesConnectivity.push_back(anIter->second);
4468 // filling the elements types
4469 SMDSAbs_ElementType aType;
4471 /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
4472 aType = SMDSAbs_Node;
4476 aType = aMeshElem->GetType();
4477 isPoly = aMeshElem->IsPoly();
4480 myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
4481 myPreviewData->elementTypes[i].isPoly = isPoly;
4482 myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
4486 myPreviewData->nodesXYZ.length( j );
4488 // filling the elements connectivities
4489 list<int>::iterator aConnIter = aNodesConnectivity.begin();
4490 myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
4491 for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
4492 myPreviewData->elementConnectivities[i] = *aConnIter;
4498 // add new nodes into myLastCreatedNodes
4499 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
4500 myLastCreatedNodes->length(aSeq.Length());
4501 for(int i=0; i<aSeq.Length(); i++)
4502 myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
4505 // add new elements into myLastCreatedElems
4506 const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
4507 myLastCreatedElems->length(aSeq.Length());
4508 for(int i=0; i<aSeq.Length(); i++)
4509 myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
4513 //================================================================================
4515 * Return data of mesh edition preview
4517 //================================================================================
4519 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
4521 return myPreviewData._retn();
4524 //================================================================================
4526 * \brief Returns list of it's IDs of created nodes
4527 * \retval SMESH::long_array* - list of node ID
4529 //================================================================================
4531 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
4533 return myLastCreatedNodes._retn();
4536 //================================================================================
4538 * \brief Returns list of it's IDs of created elements
4539 * \retval SMESH::long_array* - list of elements' ID
4541 //================================================================================
4543 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
4545 return myLastCreatedElems._retn();
4548 //=======================================================================
4549 //function : ConvertToQuadratic
4551 //=======================================================================
4553 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
4555 ::SMESH_MeshEditor anEditor( myMesh );
4556 anEditor.ConvertToQuadratic(theForce3d);
4557 TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
4558 myMesh->SetIsModified( true );
4561 //=======================================================================
4562 //function : ConvertFromQuadratic
4564 //=======================================================================
4566 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
4568 ::SMESH_MeshEditor anEditor( myMesh );
4569 CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
4570 TPythonDump() << this << ".ConvertFromQuadratic()";
4572 myMesh->SetIsModified( true );
4576 //=======================================================================
4577 //function : makeMesh
4578 //purpose : create a named imported mesh
4579 //=======================================================================
4581 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
4583 SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
4584 SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
4585 SALOMEDS::Study_var study = gen->GetCurrentStudy();
4586 SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
4587 gen->SetName( meshSO, theMeshName, "Mesh" );
4588 gen->SetPixMap( meshSO, "ICON_SMESH_TREE_MESH_IMPORTED");
4590 return mesh._retn();
4593 //=======================================================================
4594 //function : DumpGroupsList
4596 //=======================================================================
4597 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython,
4598 const SMESH::ListOfGroups * theGroupList)
4600 bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
4601 if(isDumpGroupList) {
4602 theDumpPython << theGroupList << " = ";
4606 //================================================================================
4608 \brief Generates the unique group name.
4609 \param thePrefix name prefix
4612 //================================================================================
4613 string SMESH_MeshEditor_i::generateGroupName(const string& thePrefix)
4615 SMESH::ListOfGroups_var groups = myMesh_i->GetGroups();
4616 set<string> groupNames;
4618 // Get existing group names
4619 for (int i = 0, nbGroups = groups->length(); i < nbGroups; i++ ) {
4620 SMESH::SMESH_GroupBase_var aGroup = groups[i];
4621 if (CORBA::is_nil(aGroup))
4624 groupNames.insert(aGroup->GetName());
4628 string name = thePrefix;
4631 while (!groupNames.insert(name).second) {
4636 TCollection_AsciiString nbStr(index+1);
4637 name.resize( name.rfind('_')+1 );
4638 name += nbStr.ToCString();
4646 //================================================================================
4648 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4649 \param theNodes - identifiers of nodes to be doubled
4650 \param theModifiedElems - identifiers of elements to be updated by the new (doubled)
4651 nodes. If list of element identifiers is empty then nodes are doubled but
4652 they not assigned to elements
4653 \return TRUE if operation has been completed successfully, FALSE otherwise
4654 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodeGroups()
4656 //================================================================================
4658 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodes( const SMESH::long_array& theNodes,
4659 const SMESH::long_array& theModifiedElems )
4663 ::SMESH_MeshEditor aMeshEditor( myMesh );
4664 list< int > aListOfNodes;
4666 for ( i = 0, n = theNodes.length(); i < n; i++ )
4667 aListOfNodes.push_back( theNodes[ i ] );
4669 list< int > aListOfElems;
4670 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4671 aListOfElems.push_back( theModifiedElems[ i ] );
4673 bool aResult = aMeshEditor.DoubleNodes( aListOfNodes, aListOfElems );
4675 storeResult( aMeshEditor) ;
4677 myMesh->SetIsModified( true );
4679 // Update Python script
4680 TPythonDump() << this << ".DoubleNodes( " << theNodes << ", "<< theModifiedElems << " )";
4685 //================================================================================
4687 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4688 This method provided for convenience works as DoubleNodes() described above.
4689 \param theNodeId - identifier of node to be doubled.
4690 \param theModifiedElems - identifiers of elements to be updated.
4691 \return TRUE if operation has been completed successfully, FALSE otherwise
4692 \sa DoubleNodes(), DoubleNodeGroup(), DoubleNodeGroups()
4694 //================================================================================
4696 CORBA::Boolean SMESH_MeshEditor_i::DoubleNode( CORBA::Long theNodeId,
4697 const SMESH::long_array& theModifiedElems )
4699 SMESH::long_array_var aNodes = new SMESH::long_array;
4700 aNodes->length( 1 );
4701 aNodes[ 0 ] = theNodeId;
4703 TPythonDump pyDump; // suppress dump by the next line
4705 CORBA::Boolean done = DoubleNodes( aNodes, theModifiedElems );
4707 pyDump << this << ".DoubleNode( " << theNodeId << ", " << theModifiedElems << " )";
4712 //================================================================================
4714 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4715 This method provided for convenience works as DoubleNodes() described above.
4716 \param theNodes - group of nodes to be doubled.
4717 \param theModifiedElems - group of elements to be updated.
4718 \return TRUE if operation has been completed successfully, FALSE otherwise
4719 \sa DoubleNode(), DoubleNodes(), DoubleNodeGroups()
4721 //================================================================================
4723 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroup(SMESH::SMESH_GroupBase_ptr theNodes,
4724 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4726 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4729 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4730 SMESH::long_array_var aModifiedElems;
4731 if ( !CORBA::is_nil( theModifiedElems ) )
4732 aModifiedElems = theModifiedElems->GetListOfID();
4735 aModifiedElems = new SMESH::long_array;
4736 aModifiedElems->length( 0 );
4739 TPythonDump pyDump; // suppress dump by the next line
4741 bool done = DoubleNodes( aNodes, aModifiedElems );
4743 pyDump << this << ".DoubleNodeGroup( " << theNodes << ", " << theModifiedElems << " )";
4749 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements.
4750 * Works as DoubleNodeGroup(), but returns a new group with newly created nodes.
4751 * \param theNodes - group of nodes to be doubled.
4752 * \param theModifiedElems - group of elements to be updated.
4753 * \return a new group with newly created nodes
4754 * \sa DoubleNodeGroup()
4756 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeGroupNew( SMESH::SMESH_GroupBase_ptr theNodes,
4757 SMESH::SMESH_GroupBase_ptr theModifiedElems )
4759 if ( CORBA::is_nil( theNodes ) && theNodes->GetType() != SMESH::NODE )
4762 SMESH::SMESH_Group_var aNewGroup;
4765 SMESH::long_array_var aNodes = theNodes->GetListOfID();
4766 SMESH::long_array_var aModifiedElems;
4767 if ( !CORBA::is_nil( theModifiedElems ) )
4768 aModifiedElems = theModifiedElems->GetListOfID();
4770 aModifiedElems = new SMESH::long_array;
4771 aModifiedElems->length( 0 );
4774 TPythonDump pyDump; // suppress dump by the next line
4776 bool aResult = DoubleNodes( aNodes, aModifiedElems );
4780 // Create group with newly created nodes
4781 SMESH::long_array_var anIds = GetLastCreatedNodes();
4782 if (anIds->length() > 0) {
4783 string anUnindexedName (theNodes->GetName());
4784 string aNewName = generateGroupName(anUnindexedName + "_double");
4785 aNewGroup = myMesh_i->CreateGroup(SMESH::NODE, aNewName.c_str());
4786 aNewGroup->Add(anIds);
4790 pyDump << "createdNodes = " << this << ".DoubleNodeGroupNew( " << theNodes << ", "
4791 << theModifiedElems << " )";
4793 return aNewGroup._retn();
4796 //================================================================================
4798 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4799 This method provided for convenience works as DoubleNodes() described above.
4800 \param theNodes - list of groups of nodes to be doubled
4801 \param theModifiedElems - list of groups of elements to be updated.
4802 \return TRUE if operation has been completed successfully, FALSE otherwise
4803 \sa DoubleNode(), DoubleNodeGroup(), DoubleNodes()
4805 //================================================================================
4807 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeGroups(const SMESH::ListOfGroups& theNodes,
4808 const SMESH::ListOfGroups& theModifiedElems )
4812 ::SMESH_MeshEditor aMeshEditor( myMesh );
4814 std::list< int > aNodes;
4816 for ( i = 0, n = theNodes.length(); i < n; i++ )
4818 SMESH::SMESH_GroupBase_var aGrp = theNodes[ i ];
4819 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() == SMESH::NODE )
4821 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4822 for ( j = 0, m = aCurr->length(); j < m; j++ )
4823 aNodes.push_back( aCurr[ j ] );
4827 std::list< int > anElems;
4828 for ( i = 0, n = theModifiedElems.length(); i < n; i++ )
4830 SMESH::SMESH_GroupBase_var aGrp = theModifiedElems[ i ];
4831 if ( !CORBA::is_nil( aGrp ) && aGrp->GetType() != SMESH::NODE )
4833 SMESH::long_array_var aCurr = aGrp->GetListOfID();
4834 for ( j = 0, m = aCurr->length(); j < m; j++ )
4835 anElems.push_back( aCurr[ j ] );
4839 bool aResult = aMeshEditor.DoubleNodes( aNodes, anElems );
4841 storeResult( aMeshEditor) ;
4844 myMesh->SetIsModified( true );
4847 TPythonDump() << this << ".DoubleNodeGroups( " << theNodes << ", " << theModifiedElems << " )";
4852 //================================================================================
4854 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4855 \param theElems - the list of elements (edges or faces) to be replicated
4856 The nodes for duplication could be found from these elements
4857 \param theNodesNot - list of nodes to NOT replicate
4858 \param theAffectedElems - the list of elements (cells and edges) to which the
4859 replicated nodes should be associated to.
4860 \return TRUE if operation has been completed successfully, FALSE otherwise
4861 \sa DoubleNodeGroup(), DoubleNodeGroups()
4863 //================================================================================
4865 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElem( const SMESH::long_array& theElems,
4866 const SMESH::long_array& theNodesNot,
4867 const SMESH::long_array& theAffectedElems )
4872 ::SMESH_MeshEditor aMeshEditor( myMesh );
4874 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4875 TIDSortedElemSet anElems, aNodes, anAffected;
4876 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4877 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4878 arrayToSet(theAffectedElems, aMeshDS, anAffected, SMDSAbs_All);
4880 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4882 storeResult( aMeshEditor) ;
4885 myMesh->SetIsModified( true );
4887 // Update Python script
4888 TPythonDump() << this << ".DoubleNodeElem( " << theElems << ", "
4889 << theNodesNot << ", " << theAffectedElems << " )";
4893 //================================================================================
4895 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4896 \param theElems - the list of elements (edges or faces) to be replicated
4897 The nodes for duplication could be found from these elements
4898 \param theNodesNot - list of nodes to NOT replicate
4899 \param theShape - shape to detect affected elements (element which geometric center
4900 located on or inside shape).
4901 The replicated nodes should be associated to affected elements.
4902 \return TRUE if operation has been completed successfully, FALSE otherwise
4903 \sa DoubleNodeGroupInRegion(), DoubleNodeGroupsInRegion()
4905 //================================================================================
4907 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemInRegion ( const SMESH::long_array& theElems,
4908 const SMESH::long_array& theNodesNot,
4909 GEOM::GEOM_Object_ptr theShape )
4914 ::SMESH_MeshEditor aMeshEditor( myMesh );
4916 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4917 TIDSortedElemSet anElems, aNodes;
4918 arrayToSet(theElems, aMeshDS, anElems, SMDSAbs_All);
4919 arrayToSet(theNodesNot, aMeshDS, aNodes, SMDSAbs_Node);
4921 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
4922 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
4924 storeResult( aMeshEditor) ;
4927 myMesh->SetIsModified( true );
4929 // Update Python script
4930 TPythonDump() << "isDone = " << this << ".DoubleNodeElemInRegion( " << theElems << ", "
4931 << theNodesNot << ", " << theShape << " )";
4935 //================================================================================
4937 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4938 \param theElems - group of of elements (edges or faces) to be replicated
4939 \param theNodesNot - group of nodes not to replicated
4940 \param theAffectedElems - group of elements to which the replicated nodes
4941 should be associated to.
4942 \return TRUE if operation has been completed successfully, FALSE otherwise
4943 \sa DoubleNodes(), DoubleNodeGroups()
4945 //================================================================================
4947 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroup(SMESH::SMESH_GroupBase_ptr theElems,
4948 SMESH::SMESH_GroupBase_ptr theNodesNot,
4949 SMESH::SMESH_GroupBase_ptr theAffectedElems)
4951 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4956 ::SMESH_MeshEditor aMeshEditor( myMesh );
4958 SMESHDS_Mesh* aMeshDS = GetMeshDS();
4959 TIDSortedElemSet anElems, aNodes, anAffected;
4960 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
4961 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
4962 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
4964 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
4966 storeResult( aMeshEditor) ;
4969 myMesh->SetIsModified( true );
4971 // Update Python script
4972 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroup( " << theElems << ", "
4973 << theNodesNot << ", " << theAffectedElems << " )";
4978 * \brief Creates a hole in a mesh by doubling the nodes of some particular elements
4979 * Works as DoubleNodeElemGroup(), but returns a new group with newly created elements.
4980 * \param theElems - group of of elements (edges or faces) to be replicated
4981 * \param theNodesNot - group of nodes not to replicated
4982 * \param theAffectedElems - group of elements to which the replicated nodes
4983 * should be associated to.
4984 * \return a new group with newly created elements
4985 * \sa DoubleNodeElemGroup()
4987 SMESH::SMESH_Group_ptr SMESH_MeshEditor_i::DoubleNodeElemGroupNew(SMESH::SMESH_GroupBase_ptr theElems,
4988 SMESH::SMESH_GroupBase_ptr theNodesNot,
4989 SMESH::SMESH_GroupBase_ptr theAffectedElems)
4991 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
4994 SMESH::SMESH_Group_var aNewGroup;
4998 ::SMESH_MeshEditor aMeshEditor( myMesh );
5000 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5001 TIDSortedElemSet anElems, aNodes, anAffected;
5002 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5003 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5004 idSourceToSet( theAffectedElems, aMeshDS, anAffected, SMDSAbs_All );
5007 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5009 storeResult( aMeshEditor) ;
5012 myMesh->SetIsModified( true );
5014 // Create group with newly created elements
5015 SMESH::long_array_var anIds = GetLastCreatedElems();
5016 if (anIds->length() > 0) {
5017 SMESH::ElementType aGroupType = myMesh_i->GetElementType(anIds[0], true);
5018 string anUnindexedName (theElems->GetName());
5019 string aNewName = generateGroupName(anUnindexedName + "_double");
5020 aNewGroup = myMesh_i->CreateGroup(aGroupType, aNewName.c_str());
5021 aNewGroup->Add(anIds);
5025 // Update Python script
5026 TPythonDump() << "createdElems = " << this << ".DoubleNodeElemGroupNew( " << theElems << ", "
5027 << theNodesNot << ", " << theAffectedElems << " )";
5028 return aNewGroup._retn();
5031 //================================================================================
5033 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5034 \param theElems - group of of elements (edges or faces) to be replicated
5035 \param theNodesNot - group of nodes not to replicated
5036 \param theShape - shape to detect affected elements (element which geometric center
5037 located on or inside shape).
5038 The replicated nodes should be associated to affected elements.
5039 \return TRUE if operation has been completed successfully, FALSE otherwise
5040 \sa DoubleNodesInRegion(), DoubleNodeGroupsInRegion()
5042 //================================================================================
5044 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroupInRegion(SMESH::SMESH_GroupBase_ptr theElems,
5045 SMESH::SMESH_GroupBase_ptr theNodesNot,
5046 GEOM::GEOM_Object_ptr theShape )
5049 if ( CORBA::is_nil( theElems ) && theElems->GetType() == SMESH::NODE )
5054 ::SMESH_MeshEditor aMeshEditor( myMesh );
5056 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5057 TIDSortedElemSet anElems, aNodes, anAffected;
5058 idSourceToSet( theElems, aMeshDS, anElems, SMDSAbs_All );
5059 idSourceToSet( theNodesNot, aMeshDS, aNodes, SMDSAbs_Node );
5061 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5062 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5064 storeResult( aMeshEditor) ;
5067 myMesh->SetIsModified( true );
5069 // Update Python script
5070 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupInRegion( " << theElems << ", "
5071 << theNodesNot << ", " << theShape << " )";
5075 //================================================================================
5077 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5078 This method provided for convenience works as DoubleNodes() described above.
5079 \param theElems - list of groups of elements (edges or faces) to be replicated
5080 \param theNodesNot - list of groups of nodes not to replicated
5081 \param theAffectedElems - group of elements to which the replicated nodes
5082 should be associated to.
5083 \return TRUE if operation has been completed successfully, FALSE otherwise
5084 \sa DoubleNodeGroup(), DoubleNodes()
5086 //================================================================================
5088 static void listOfGroupToSet(const SMESH::ListOfGroups& theGrpList,
5089 SMESHDS_Mesh* theMeshDS,
5090 TIDSortedElemSet& theElemSet,
5091 const bool theIsNodeGrp)
5093 for ( int i = 0, n = theGrpList.length(); i < n; i++ )
5095 SMESH::SMESH_GroupBase_var aGrp = theGrpList[ i ];
5096 if ( !CORBA::is_nil( aGrp ) && (theIsNodeGrp ? aGrp->GetType() == SMESH::NODE
5097 : aGrp->GetType() != SMESH::NODE ) )
5099 SMESH::long_array_var anIDs = aGrp->GetIDs();
5100 arrayToSet( anIDs, theMeshDS, theElemSet, theIsNodeGrp ? SMDSAbs_Node : SMDSAbs_All );
5105 CORBA::Boolean SMESH_MeshEditor_i::DoubleNodeElemGroups(const SMESH::ListOfGroups& theElems,
5106 const SMESH::ListOfGroups& theNodesNot,
5107 const SMESH::ListOfGroups& theAffectedElems)
5111 ::SMESH_MeshEditor aMeshEditor( myMesh );
5113 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5114 TIDSortedElemSet anElems, aNodes, anAffected;
5115 listOfGroupToSet(theElems, aMeshDS, anElems, false );
5116 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5117 listOfGroupToSet(theAffectedElems, aMeshDS, anAffected, false );
5119 bool aResult = aMeshEditor.DoubleNodes( anElems, aNodes, anAffected );
5121 storeResult( aMeshEditor) ;
5124 myMesh->SetIsModified( true );
5126 // Update Python script
5127 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroups( " << &theElems << ", "
5128 << &theNodesNot << ", " << &theAffectedElems << " )";
5132 //================================================================================
5134 \brief Creates a hole in a mesh by doubling the nodes of some particular elements
5135 This method provided for convenience works as DoubleNodes() described above.
5136 \param theElems - list of groups of elements (edges or faces) to be replicated
5137 \param theNodesNot - list of groups of nodes not to replicated
5138 \param theShape - shape to detect affected elements (element which geometric center
5139 located on or inside shape).
5140 The replicated nodes should be associated to affected elements.
5141 \return TRUE if operation has been completed successfully, FALSE otherwise
5142 \sa DoubleNodeGroupInRegion(), DoubleNodesInRegion()
5144 //================================================================================
5147 SMESH_MeshEditor_i::DoubleNodeElemGroupsInRegion(const SMESH::ListOfGroups& theElems,
5148 const SMESH::ListOfGroups& theNodesNot,
5149 GEOM::GEOM_Object_ptr theShape )
5153 ::SMESH_MeshEditor aMeshEditor( myMesh );
5155 SMESHDS_Mesh* aMeshDS = GetMeshDS();
5156 TIDSortedElemSet anElems, aNodes;
5157 listOfGroupToSet(theElems, aMeshDS, anElems,false );
5158 listOfGroupToSet(theNodesNot, aMeshDS, aNodes, true );
5160 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape );
5161 bool aResult = aMeshEditor.DoubleNodesInRegion( anElems, aNodes, aShape );
5163 storeResult( aMeshEditor) ;
5166 myMesh->SetIsModified( true );
5168 // Update Python script
5169 TPythonDump() << "isDone = " << this << ".DoubleNodeElemGroupsInRegion( " << &theElems << ", "
5170 << &theNodesNot << ", " << theShape << " )";
5174 //================================================================================
5176 \brief Generated skin mesh (containing 2D cells) from 3D mesh
5177 The created 2D mesh elements based on nodes of free faces of boundary volumes
5178 \return TRUE if operation has been completed successfully, FALSE otherwise
5180 //================================================================================
5182 CORBA::Boolean SMESH_MeshEditor_i::Make2DMeshFrom3D()
5186 ::SMESH_MeshEditor aMeshEditor( myMesh );
5187 bool aResult = aMeshEditor.Make2DMeshFrom3D();
5188 storeResult( aMeshEditor) ;
5190 TPythonDump() << "isDone = " << this << ".Make2DMeshFrom3D()";
5194 //================================================================================
5196 * \brief Creates missing boundary elements
5197 * \param elements - elements whose boundary is to be checked
5198 * \param dimension - defines type of boundary elements to create
5199 * \param groupName - a name of group to store created boundary elements in,
5200 * "" means not to create the group
5201 * \param meshName - a name of new mesh to store created boundary elements in,
5202 * "" means not to create the new mesh
5203 * \param toCopyElements - if true, the checked elements will be copied into the new mesh
5204 * \param toCopyExistingBondary - if true, not only new but also pre-existing
5205 * boundary elements will be copied into the new mesh
5206 * \param group - returns the create group, if any
5207 * \retval SMESH::SMESH_Mesh - the mesh where elements were added to
5209 //================================================================================
5211 SMESH::SMESH_Mesh_ptr
5212 SMESH_MeshEditor_i::MakeBoundaryMesh(SMESH::SMESH_IDSource_ptr elements,
5213 SMESH::Bnd_Dimension dimension,
5214 const char* groupName,
5215 const char* meshName,
5216 CORBA::Boolean toCopyElements,
5217 CORBA::Boolean toCopyMissingBondary,
5218 SMESH::SMESH_Group_out group)
5221 return SMESH::SMESH_Mesh::_duplicate( myMesh_i->_this() );