1 // SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESH_MeshEditor_i.cxx
25 // Author : Nicolas REJNERI
29 #include "SMESH_MeshEditor_i.hxx"
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
35 #include "SMESH_MeshEditor.hxx"
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
40 #include "utilities.h"
50 //=======================================================================
52 //purpose : put array contents into theStr like this: "[ 1, 2, 5 ]"
53 //=======================================================================
55 template <class _array>
56 TCollection_AsciiString& addArray(TCollection_AsciiString& theStr,
59 ostringstream sout; // can convert long int, and TCollection_AsciiString cant
61 for (int i = 1; i <= IDs.length(); i++) {
63 if ( i < IDs.length() )
67 theStr += (char*) sout.str().c_str();
71 //=======================================================================
72 //function : addObject
73 //purpose : add object to script string
74 //=======================================================================
76 static TCollection_AsciiString& addObject(TCollection_AsciiString& theStr,
77 CORBA::Object_ptr theObject)
79 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
80 SALOMEDS::SObject_var aSO =
81 aSMESHGen->ObjectToSObject(aSMESHGen->GetCurrentStudy(), theObject);
82 if ( !aSO->_is_nil() )
83 theStr += aSO->GetID();
84 else if ( !CORBA::is_nil( theObject ) )
85 theStr += aSMESHGen->GetORB()->object_to_string( theObject );
91 //=======================================================================
94 //=======================================================================
96 static TCollection_AsciiString& addAxis(TCollection_AsciiString& theStr,
97 const SMESH::AxisStruct & theAxis)
99 theStr += "SMESH.AxisStruct( ";
100 theStr += TCollection_AsciiString( theAxis.x ) + ", ";
101 theStr += TCollection_AsciiString( theAxis.y ) + ", ";
102 theStr += TCollection_AsciiString( theAxis.z ) + ", ";
103 theStr += TCollection_AsciiString( theAxis.vx ) + ", ";
104 theStr += TCollection_AsciiString( theAxis.vy ) + ", ";
105 theStr += TCollection_AsciiString( theAxis.vz ) + " )";
109 //=======================================================================
110 //function : addToPythonScript
111 //purpose : add theStr to python script of the current study
112 //=======================================================================
114 static inline void addToPythonScript(const TCollection_AsciiString& theStr)
116 SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
117 aSMESHGen->AddToPythonScript(aSMESHGen->GetCurrentStudy()->StudyId(), theStr);
120 //=============================================================================
124 //=============================================================================
126 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh)
131 //=============================================================================
135 //=============================================================================
138 SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
140 ::SMESH_MeshEditor anEditor( _myMesh );
143 for (int i = 0; i < IDsOfElements.length(); i++)
144 IdList.push_back( IDsOfElements[i] );
146 // Update Python script
147 TCollection_AsciiString str ("isDone = mesh_editor.RemoveElements(");
148 addArray( str, IDsOfElements ) += ")";
149 addToPythonScript( str );
151 addToPythonScript( "print \"RemoveElements: \", isDone" );
154 return anEditor.Remove( IdList, false );
157 //=============================================================================
161 //=============================================================================
163 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
164 long_array & IDsOfNodes)
166 ::SMESH_MeshEditor anEditor( _myMesh );
168 for (int i = 0; i < IDsOfNodes.length(); i++)
169 IdList.push_back( IDsOfNodes[i] );
171 // Update Python script
172 TCollection_AsciiString str ("isDone = mesh_editor.RemoveNodes(");
173 addArray( str, IDsOfNodes ) += ")";
174 addToPythonScript( str );
176 addToPythonScript( "print \"RemoveNodes: \", isDone" );
179 return anEditor.Remove( IdList, true );
182 //=============================================================================
186 //=============================================================================
188 CORBA::Boolean SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
190 int NbNodes = IDsOfNodes.length();
193 CORBA::Long index1 = IDsOfNodes[0];
194 CORBA::Long index2 = IDsOfNodes[1];
195 GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
197 // Update Python script
198 TCollection_AsciiString str ("isDone = mesh_editor.AddEdge([");
199 str += TCollection_AsciiString((int) index1) + ", ";
200 str += TCollection_AsciiString((int) index2) + " ])";
201 addToPythonScript( str );
206 //=============================================================================
210 //=============================================================================
212 CORBA::Boolean SMESH_MeshEditor_i::AddNode(CORBA::Double x,
213 CORBA::Double y, CORBA::Double z)
215 GetMeshDS()->AddNode(x, y, z);
217 // Update Python script
218 TCollection_AsciiString str ("isDone = mesh_editor.AddNode(");
219 str += TCollection_AsciiString( x ) + ", ";
220 str += TCollection_AsciiString( y ) + ", ";
221 str += TCollection_AsciiString( z ) + " )";
222 addToPythonScript( str );
227 //=============================================================================
231 //=============================================================================
233 CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
235 int NbNodes = IDsOfNodes.length();
241 std::vector<const SMDS_MeshNode*> nodes (NbNodes);
242 for (int i = 0; i < NbNodes; i++)
243 nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
247 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
249 else if (NbNodes == 4)
251 GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
255 GetMeshDS()->AddPolygonalFace(nodes);
258 // Update Python script
259 TCollection_AsciiString str ("isDone = mesh_editor.AddFace(");
260 addArray( str, IDsOfNodes ) += ")";
261 addToPythonScript( str );
263 addToPythonScript( "print \"AddFace: \", isDone" );
269 //=============================================================================
273 //=============================================================================
275 CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
276 long_array & IDsOfNodes)
278 int NbNodes = IDsOfNodes.length();
279 vector< const SMDS_MeshNode*> n(NbNodes);
280 for(int i=0;i<NbNodes;i++)
281 n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
285 case 4:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
286 case 5:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
287 case 6:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
288 case 8:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
290 // Update Python script
291 TCollection_AsciiString str ("isDone = mesh_editor.AddVolume(");
292 addArray( str, IDsOfNodes ) += ")";
293 addToPythonScript( str );
295 addToPythonScript( "print \"AddVolume: \", isDone" );
301 //=============================================================================
303 * AddPolyhedralVolume
305 //=============================================================================
306 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolume
307 (const SMESH::long_array & IDsOfNodes,
308 const SMESH::long_array & Quantities)
310 int NbNodes = IDsOfNodes.length();
311 std::vector<const SMDS_MeshNode*> n (NbNodes);
312 for (int i = 0; i < NbNodes; i++)
313 n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
315 int NbFaces = Quantities.length();
316 std::vector<int> q (NbFaces);
317 for (int j = 0; j < NbFaces; j++)
318 q[j] = Quantities[j];
320 GetMeshDS()->AddPolyhedralVolume(n, q);
322 // Update Python script
323 TCollection_AsciiString str ("isDone = mesh_editor.AddPolyhedralVolume(");
324 addArray( str, IDsOfNodes ) += ", ";
325 addArray( str, Quantities ) += ")";
326 addToPythonScript( str );
328 addToPythonScript( "print \"AddPolyhedralVolume: \", isDone" );
334 //=============================================================================
336 * AddPolyhedralVolumeByFaces
338 //=============================================================================
339 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
340 (const SMESH::long_array & IdsOfFaces)
342 int NbFaces = IdsOfFaces.length();
343 std::vector<const SMDS_MeshNode*> poly_nodes;
344 std::vector<int> quantities (NbFaces);
346 for (int i = 0; i < NbFaces; i++) {
347 const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
348 quantities[i] = aFace->NbNodes();
350 SMDS_ElemIteratorPtr It = aFace->nodesIterator();
352 poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
356 GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
358 // Update Python script
359 TCollection_AsciiString str ("isDone = mesh_editor.AddPolyhedralVolumeByFaces(");
360 addArray( str, IdsOfFaces ) += ")";
361 addToPythonScript( str );
363 addToPythonScript( "print \"AddPolyhedralVolume: \", isDone" );
369 //=============================================================================
373 //=============================================================================
375 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long NodeID,
380 const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
384 GetMeshDS()->MoveNode(node, x, y, z);
386 // Update Python script
387 TCollection_AsciiString str ("isDone = mesh_editor.MoveNode(");
388 str += TCollection_AsciiString((Standard_Integer) NodeID) + ", ";
389 str += TCollection_AsciiString((Standard_Real) x) + ", ";
390 str += TCollection_AsciiString((Standard_Real) y) + ", ";
391 str += TCollection_AsciiString((Standard_Real) z) + " )";
392 addToPythonScript( str );
397 //=============================================================================
401 //=============================================================================
403 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
406 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
407 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
411 // Update Python script
412 TCollection_AsciiString str ("isDone = mesh_editor.InverseDiag(");
413 str += TCollection_AsciiString((Standard_Integer) NodeID1) + ", ";
414 str += TCollection_AsciiString((Standard_Integer) NodeID2) + " )";
415 addToPythonScript( str );
417 ::SMESH_MeshEditor aMeshEditor( _myMesh );
418 return aMeshEditor.InverseDiag ( n1, n2 );
421 //=============================================================================
425 //=============================================================================
427 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
430 const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
431 const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
435 // Update Python script
436 TCollection_AsciiString str ("isDone = mesh_editor.DeleteDiag(");
437 str += TCollection_AsciiString((Standard_Integer) NodeID1) + ", ";
438 str += TCollection_AsciiString((Standard_Integer) NodeID2) + " )";
439 addToPythonScript( str );
441 ::SMESH_MeshEditor aMeshEditor( _myMesh );
442 return aMeshEditor.DeleteDiag ( n1, n2 );
445 //=============================================================================
449 //=============================================================================
451 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
453 ::SMESH_MeshEditor anEditor( _myMesh );
454 for (int i = 0; i < IDsOfElements.length(); i++)
456 CORBA::Long index = IDsOfElements[i];
457 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
459 anEditor.Reorient( elem );
461 // Update Python script
462 TCollection_AsciiString str ("isDone = mesh_editor.Reorient(");
463 addArray( str, IDsOfElements ) += ")";
464 addToPythonScript( str );
466 addToPythonScript( "print \"Reorient: \", isDone" );
473 //=============================================================================
477 //=============================================================================
479 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
481 SMESH::long_array_var anElementsId = theObject->GetIDs();
482 return Reorient(anElementsId);
485 //=============================================================================
489 //=============================================================================
492 SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array & IDsOfElements,
493 SMESH::NumericalFunctor_ptr Criterion,
494 CORBA::Double MaxAngle)
496 set<const SMDS_MeshElement*> faces;
497 for (int i = 0; i < IDsOfElements.length(); i++)
499 CORBA::Long index = IDsOfElements[i];
500 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
501 if ( elem && elem->GetType() == SMDSAbs_Face)
502 faces.insert( elem );
504 SMESH::NumericalFunctor_i* aNumericalFunctor =
505 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
506 SMESH::Controls::NumericalFunctorPtr aCrit;
507 if ( !aNumericalFunctor )
508 aCrit.reset( new SMESH::Controls::AspectRatio() );
510 aCrit = aNumericalFunctor->GetNumericalFunctor();
512 // Update Python script
513 TCollection_AsciiString str ("isDone = mesh_editor.TriToQuad(");
514 addArray( str, IDsOfElements ) += ", None, ";
515 str += (Standard_Real) MaxAngle;
516 addToPythonScript( str + ")" );
518 addToPythonScript( "print \"TriToQuad: \", isDone" );
521 ::SMESH_MeshEditor anEditor( _myMesh );
522 return anEditor.TriToQuad( faces, aCrit, MaxAngle );
525 //=============================================================================
529 //=============================================================================
532 SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr theObject,
533 SMESH::NumericalFunctor_ptr Criterion,
534 CORBA::Double MaxAngle)
536 SMESH::long_array_var anElementsId = theObject->GetIDs();
537 return TriToQuad(anElementsId, Criterion, MaxAngle);
540 //=============================================================================
544 //=============================================================================
547 SMESH_MeshEditor_i::QuadToTri(const SMESH::long_array & IDsOfElements,
548 SMESH::NumericalFunctor_ptr Criterion)
550 set<const SMDS_MeshElement*> faces;
551 for (int i = 0; i < IDsOfElements.length(); i++)
553 CORBA::Long index = IDsOfElements[i];
554 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
555 if ( elem && elem->GetType() == SMDSAbs_Face)
556 faces.insert( elem );
558 SMESH::NumericalFunctor_i* aNumericalFunctor =
559 dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
560 SMESH::Controls::NumericalFunctorPtr aCrit;
561 if ( !aNumericalFunctor )
562 aCrit.reset( new SMESH::Controls::AspectRatio() );
564 aCrit = aNumericalFunctor->GetNumericalFunctor();
567 // Update Python script
568 TCollection_AsciiString str ("isDone = mesh_editor.QuadToTri(");
569 addArray( str, IDsOfElements ) += ", None ), ";
570 addToPythonScript( str );
572 addToPythonScript( "print \"QuadToTri: \", isDone" );
575 ::SMESH_MeshEditor anEditor( _myMesh );
576 return anEditor.QuadToTri( faces, aCrit );
579 //=============================================================================
583 //=============================================================================
586 SMESH_MeshEditor_i::SplitQuad(const SMESH::long_array & IDsOfElements,
587 CORBA::Boolean Diag13)
589 set<const SMDS_MeshElement*> faces;
590 for (int i = 0; i < IDsOfElements.length(); i++)
592 CORBA::Long index = IDsOfElements[i];
593 const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
594 if ( elem && elem->GetType() == SMDSAbs_Face)
595 faces.insert( elem );
598 // Update Python script
599 TCollection_AsciiString str ("isDone = mesh_editor.SplitQuad(");
600 addArray( str, IDsOfElements ) += ", ";
601 str += TCollection_AsciiString( Diag13 );
602 addToPythonScript( str + ")" );
604 addToPythonScript( "print \"SplitQuad: \", isDone" );
607 ::SMESH_MeshEditor anEditor( _myMesh );
608 return anEditor.QuadToTri( faces, Diag13 );
611 //=============================================================================
615 //=============================================================================
618 SMESH_MeshEditor_i::SplitQuadObject(SMESH::SMESH_IDSource_ptr theObject,
619 CORBA::Boolean Diag13)
621 SMESH::long_array_var anElementsId = theObject->GetIDs();
622 return SplitQuad(anElementsId, Diag13);
625 //=============================================================================
629 //=============================================================================
632 SMESH_MeshEditor_i::Smooth(const SMESH::long_array & IDsOfElements,
633 const SMESH::long_array & IDsOfFixedNodes,
634 CORBA::Long MaxNbOfIterations,
635 CORBA::Double MaxAspectRatio,
636 SMESH::SMESH_MeshEditor::Smooth_Method Method)
638 SMESHDS_Mesh* aMesh = GetMeshDS();
640 set<const SMDS_MeshElement*> elements;
641 for (int i = 0; i < IDsOfElements.length(); i++)
643 CORBA::Long index = IDsOfElements[i];
644 const SMDS_MeshElement * elem = aMesh->FindElement(index);
645 if ( elem && elem->GetType() == SMDSAbs_Face)
646 elements.insert( elem );
649 set<const SMDS_MeshNode*> fixedNodes;
650 for (int i = 0; i < IDsOfFixedNodes.length(); i++)
652 CORBA::Long index = IDsOfFixedNodes[i];
653 const SMDS_MeshNode * node = aMesh->FindNode(index);
655 fixedNodes.insert( node );
657 ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
658 if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
659 method = ::SMESH_MeshEditor::CENTROIDAL;
661 ::SMESH_MeshEditor anEditor( _myMesh );
662 anEditor.Smooth( elements, fixedNodes, method, MaxNbOfIterations, MaxAspectRatio );
664 // Update Python script
665 TCollection_AsciiString str ("isDone = mesh_editor.Smooth(");
666 addArray( str, IDsOfElements ) += ", ";
667 addArray( str, IDsOfFixedNodes ) += ", ";
668 str += (Standard_Integer) MaxNbOfIterations;
670 str += (Standard_Real) MaxAspectRatio;
672 if ( method == ::SMESH_MeshEditor::CENTROIDAL )
673 str += "SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH )";
675 str += "SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH )";
676 addToPythonScript( str );
678 addToPythonScript( "print \"SplitQuad: \", isDone" );
684 //=============================================================================
688 //=============================================================================
691 SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr theObject,
692 const SMESH::long_array & IDsOfFixedNodes,
693 CORBA::Long MaxNbOfIterations,
694 CORBA::Double MaxAspectRatio,
695 SMESH::SMESH_MeshEditor::Smooth_Method Method)
697 SMESH::long_array_var anElementsId = theObject->GetIDs();
698 return Smooth(anElementsId, IDsOfFixedNodes, MaxNbOfIterations, MaxAspectRatio, Method);
701 //=============================================================================
705 //=============================================================================
707 void SMESH_MeshEditor_i::RenumberNodes()
709 // Update Python script
710 addToPythonScript( "mesh_editor.RenumberNodes()" );
712 GetMeshDS()->Renumber( true );
715 //=============================================================================
719 //=============================================================================
721 void SMESH_MeshEditor_i::RenumberElements()
723 // Update Python script
724 addToPythonScript( "mesh_editor.RenumberElements()" );
726 GetMeshDS()->Renumber( false );
729 //=======================================================================
730 //function : RotationSweep
732 //=======================================================================
734 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
735 const SMESH::AxisStruct & theAxis,
736 CORBA::Double theAngleInRadians,
737 CORBA::Long theNbOfSteps,
738 CORBA::Double theTolerance)
740 SMESHDS_Mesh* aMesh = GetMeshDS();
742 set<const SMDS_MeshElement*> elements;
743 for (int i = 0; i < theIDsOfElements.length(); i++)
745 CORBA::Long index = theIDsOfElements[i];
746 const SMDS_MeshElement * elem = aMesh->FindElement(index);
748 elements.insert( elem );
750 gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
751 gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
753 ::SMESH_MeshEditor anEditor( _myMesh );
754 anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
755 theNbOfSteps, theTolerance);
757 // Update Python script
758 TCollection_AsciiString str = "axis = ";
759 addAxis( str, theAxis );
760 addToPythonScript( str );
761 str = ("mesh_editor.RotationSweep(");
762 addArray( str, theIDsOfElements ) += ", axis, ";
763 str += TCollection_AsciiString( theAngleInRadians ) + ", ";
764 str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
765 str += TCollection_AsciiString( theTolerance ) + " )";
766 addToPythonScript( str );
769 //=======================================================================
770 //function : RotationSweepObject
772 //=======================================================================
774 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
775 const SMESH::AxisStruct & theAxis,
776 CORBA::Double theAngleInRadians,
777 CORBA::Long theNbOfSteps,
778 CORBA::Double theTolerance)
780 SMESH::long_array_var anElementsId = theObject->GetIDs();
781 RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
784 //=======================================================================
785 //function : ExtrusionSweep
787 //=======================================================================
789 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
790 const SMESH::DirStruct & theStepVector,
791 CORBA::Long theNbOfSteps)
793 SMESHDS_Mesh* aMesh = GetMeshDS();
795 set<const SMDS_MeshElement*> elements;
796 for (int i = 0; i < theIDsOfElements.length(); i++)
798 CORBA::Long index = theIDsOfElements[i];
799 const SMDS_MeshElement * elem = aMesh->FindElement(index);
801 elements.insert( elem );
803 const SMESH::PointStruct * P = &theStepVector.PS;
804 gp_Vec stepVec( P->x, P->y, P->z );
806 ::SMESH_MeshEditor anEditor( _myMesh );
807 anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
809 // Update Python script
810 TCollection_AsciiString str = "stepVector = SMESH.DirStruct( SMESH.PointStruct ( ";
811 str += (TCollection_AsciiString) stepVec.X() + ", ";
812 str += (TCollection_AsciiString) stepVec.Y() + ", ";
813 str += (TCollection_AsciiString) stepVec.Z() + " ))";
814 addToPythonScript( str );
815 str = ("mesh_editor.ExtrusionSweep(");
816 addArray( str, theIDsOfElements ) += ", stepVector, ";
817 str += TCollection_AsciiString((int)theNbOfSteps) + " )";
818 addToPythonScript( str );
822 //=======================================================================
823 //function : ExtrusionSweepObject
825 //=======================================================================
827 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
828 const SMESH::DirStruct & theStepVector,
829 CORBA::Long theNbOfSteps)
831 SMESH::long_array_var anElementsId = theObject->GetIDs();
832 ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
835 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
837 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
841 RETCASE( EXTR_NO_ELEMENTS );
842 RETCASE( EXTR_PATH_NOT_EDGE );
843 RETCASE( EXTR_BAD_PATH_SHAPE );
844 RETCASE( EXTR_BAD_STARTING_NODE );
845 RETCASE( EXTR_BAD_ANGLES_NUMBER );
846 RETCASE( EXTR_CANT_GET_TANGENT );
848 return SMESH::SMESH_MeshEditor::EXTR_OK;
851 //=======================================================================
852 //function : ExtrusionAlongPath
854 //=======================================================================
856 SMESH::SMESH_MeshEditor::Extrusion_Error
857 SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array & theIDsOfElements,
858 SMESH::SMESH_Mesh_ptr thePathMesh,
859 GEOM::GEOM_Object_ptr thePathShape,
860 CORBA::Long theNodeStart,
861 CORBA::Boolean theHasAngles,
862 const SMESH::double_array & theAngles,
863 CORBA::Boolean theHasRefPoint,
864 const SMESH::PointStruct & theRefPoint)
866 SMESHDS_Mesh* aMesh = GetMeshDS();
868 if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
869 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
871 SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
872 TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
873 SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
876 return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
878 SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
880 return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
882 set<const SMDS_MeshElement*> elements;
883 for (int i = 0; i < theIDsOfElements.length(); i++)
885 CORBA::Long index = theIDsOfElements[i];
886 const SMDS_MeshElement * elem = aMesh->FindElement(index);
888 elements.insert( elem );
892 for (int i = 0; i < theAngles.length(); i++)
894 angles.push_back( theAngles[i] );
897 gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
899 // Update Python script
900 TCollection_AsciiString str = "refPoint = SMESH.PointStruct( ";
901 str += (TCollection_AsciiString) refPnt.X() + ", ";
902 str += (TCollection_AsciiString) refPnt.Y() + ", ";
903 str += (TCollection_AsciiString) refPnt.Z() + " )";
904 addToPythonScript( str );
905 str = ("error = mesh_editor.ExtrusionAlongPath(");
906 addArray ( str, theIDsOfElements ) += ", ";
907 addObject( str, thePathMesh ) += ", salome.IDToObject(\"";
908 addObject( str, thePathShape ) += "\"), ";
909 str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
910 str += TCollection_AsciiString( (int)theHasAngles ) + ", ";
911 addArray ( str, theAngles ) += ", ";
912 str += (TCollection_AsciiString) theHasRefPoint + ", refPoint )";
913 addToPythonScript( str );
915 ::SMESH_MeshEditor anEditor( _myMesh );
916 return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ) );
919 //=======================================================================
920 //function : ExtrusionAlongPathObject
922 //=======================================================================
924 SMESH::SMESH_MeshEditor::Extrusion_Error
925 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr theObject,
926 SMESH::SMESH_Mesh_ptr thePathMesh,
927 GEOM::GEOM_Object_ptr thePathShape,
928 CORBA::Long theNodeStart,
929 CORBA::Boolean theHasAngles,
930 const SMESH::double_array & theAngles,
931 CORBA::Boolean theHasRefPoint,
932 const SMESH::PointStruct & theRefPoint)
934 SMESH::long_array_var anElementsId = theObject->GetIDs();
935 return ExtrusionAlongPath( anElementsId, thePathMesh, thePathShape, theNodeStart, theHasAngles, theAngles, theHasRefPoint, theRefPoint );
938 //=======================================================================
941 //=======================================================================
943 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array & theIDsOfElements,
944 const SMESH::AxisStruct & theAxis,
945 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
946 CORBA::Boolean theCopy)
948 SMESHDS_Mesh* aMesh = GetMeshDS();
950 set<const SMDS_MeshElement*> elements;
951 for (int i = 0; i < theIDsOfElements.length(); i++)
953 CORBA::Long index = theIDsOfElements[i];
954 const SMDS_MeshElement * elem = aMesh->FindElement(index);
956 elements.insert( elem );
958 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
959 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
962 TCollection_AsciiString typeStr, copyStr( theCopy );
963 switch ( theMirrorType ) {
964 case SMESH::SMESH_MeshEditor::POINT:
965 aTrsf.SetMirror( P );
966 typeStr = "SMESH.SMESH_MeshEditor.POINT";
968 case SMESH::SMESH_MeshEditor::AXIS:
969 aTrsf.SetMirror( gp_Ax1( P, V ));
970 typeStr = "SMESH.SMESH_MeshEditor.AXIS";
973 aTrsf.SetMirror( gp_Ax2( P, V ));
974 typeStr = "SMESH.SMESH_MeshEditor.PLANE";
977 // Update Python script
978 TCollection_AsciiString str ("mesh_editor.Mirror(");
979 addArray( str, theIDsOfElements ) += ", ";
980 addAxis( str, theAxis ) += ", ";
981 str += typeStr + ", ";
982 str += copyStr + " )";
983 addToPythonScript( str );
985 ::SMESH_MeshEditor anEditor( _myMesh );
986 anEditor.Transform (elements, aTrsf, theCopy);
989 //=======================================================================
990 //function : MirrorObject
992 //=======================================================================
994 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr theObject,
995 const SMESH::AxisStruct & theAxis,
996 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
997 CORBA::Boolean theCopy)
999 SMESH::long_array_var anElementsId = theObject->GetIDs();
1000 Mirror(anElementsId, theAxis, theMirrorType, theCopy);
1003 //=======================================================================
1004 //function : Translate
1006 //=======================================================================
1008 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
1009 const SMESH::DirStruct & theVector,
1010 CORBA::Boolean theCopy)
1012 SMESHDS_Mesh* aMesh = GetMeshDS();
1014 set<const SMDS_MeshElement*> elements;
1015 for (int i = 0; i < theIDsOfElements.length(); i++)
1017 CORBA::Long index = theIDsOfElements[i];
1018 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1020 elements.insert( elem );
1023 const SMESH::PointStruct * P = &theVector.PS;
1024 aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
1026 ::SMESH_MeshEditor anEditor( _myMesh );
1027 anEditor.Transform (elements, aTrsf, theCopy);
1029 // Update Python script
1030 TCollection_AsciiString str = "vector = SMESH.DirStruct( SMESH.PointStruct ( ";
1031 str += (TCollection_AsciiString) P->x + ", ";
1032 str += (TCollection_AsciiString) P->y + ", ";
1033 str += (TCollection_AsciiString) P->z + " ))";
1034 addToPythonScript( str );
1035 str = ("mesh_editor.Translate(");
1036 addArray( str, theIDsOfElements ) += ", vector, ";
1037 str += (TCollection_AsciiString) theCopy + " )";
1038 addToPythonScript( str );
1041 //=======================================================================
1042 //function : TranslateObject
1044 //=======================================================================
1046 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
1047 const SMESH::DirStruct & theVector,
1048 CORBA::Boolean theCopy)
1050 SMESH::long_array_var anElementsId = theObject->GetIDs();
1051 Translate(anElementsId, theVector, theCopy);
1054 //=======================================================================
1057 //=======================================================================
1059 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
1060 const SMESH::AxisStruct & theAxis,
1061 CORBA::Double theAngle,
1062 CORBA::Boolean theCopy)
1064 SMESHDS_Mesh* aMesh = GetMeshDS();
1066 set<const SMDS_MeshElement*> elements;
1067 for (int i = 0; i < theIDsOfElements.length(); i++)
1069 CORBA::Long index = theIDsOfElements[i];
1070 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1072 elements.insert( elem );
1074 gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1075 gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1078 aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
1080 ::SMESH_MeshEditor anEditor( _myMesh );
1081 anEditor.Transform (elements, aTrsf, theCopy);
1083 // Update Python script
1084 TCollection_AsciiString str ("axis = ");
1085 addAxis( str, theAxis );
1086 addToPythonScript( str );
1087 str = ("mesh_editor.Rotate(");
1088 addArray( str, theIDsOfElements ) += ", axis, ";
1089 str += (TCollection_AsciiString) theAngle + ", ";
1090 str += (TCollection_AsciiString) theCopy + " )";
1091 addToPythonScript( str );
1094 //=======================================================================
1095 //function : RotateObject
1097 //=======================================================================
1099 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
1100 const SMESH::AxisStruct & theAxis,
1101 CORBA::Double theAngle,
1102 CORBA::Boolean theCopy)
1104 SMESH::long_array_var anElementsId = theObject->GetIDs();
1105 Rotate(anElementsId, theAxis, theAngle, theCopy);
1108 //=======================================================================
1109 //function : FindCoincidentNodes
1111 //=======================================================================
1113 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double Tolerance,
1114 SMESH::array_of_long_array_out GroupsOfNodes)
1116 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1117 ::SMESH_MeshEditor anEditor( _myMesh );
1118 set<const SMDS_MeshNode*> nodes; // no input nodes
1119 anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
1121 GroupsOfNodes = new SMESH::array_of_long_array;
1122 GroupsOfNodes->length( aListOfListOfNodes.size() );
1123 ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
1124 for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
1126 list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
1127 list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
1128 SMESH::long_array& aGroup = GroupsOfNodes[ i ];
1129 aGroup.length( aListOfNodes.size() );
1130 for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
1131 aGroup[ j ] = (*lIt)->GetID();
1135 //=======================================================================
1136 //function : MergeNodes
1138 //=======================================================================
1140 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
1142 SMESHDS_Mesh* aMesh = GetMeshDS();
1144 TCollection_AsciiString str( "mesh_editor.MergeNodes([" );
1145 ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1146 for (int i = 0; i < GroupsOfNodes.length(); i++)
1148 const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
1149 aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
1150 list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
1151 for ( int j = 0; j < aNodeGroup.length(); j++ )
1153 CORBA::Long index = aNodeGroup[ j ];
1154 const SMDS_MeshNode * node = aMesh->FindNode(index);
1156 aListOfNodes.push_back( node );
1158 if ( aListOfNodes.size() < 2 )
1159 aListOfListOfNodes.pop_back();
1163 addArray( str, aNodeGroup );
1165 ::SMESH_MeshEditor anEditor( _myMesh );
1166 anEditor.MergeNodes( aListOfListOfNodes );
1168 // Update Python script
1169 addToPythonScript( str + "])" );
1172 //=======================================================================
1173 //function : MergeEqualElements
1175 //=======================================================================
1177 void SMESH_MeshEditor_i::MergeEqualElements()
1179 ::SMESH_MeshEditor anEditor( _myMesh );
1180 anEditor.MergeEqualElements();
1182 // Update Python script
1183 addToPythonScript( "mesh_editor.MergeEqualElements()" );
1186 //=======================================================================
1187 //function : operator
1189 //=======================================================================
1191 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1193 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
1197 RETCASE( SEW_BORDER1_NOT_FOUND );
1198 RETCASE( SEW_BORDER2_NOT_FOUND );
1199 RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
1200 RETCASE( SEW_BAD_SIDE_NODES );
1201 RETCASE( SEW_VOLUMES_TO_SPLIT );
1202 RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
1203 RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
1204 RETCASE( SEW_BAD_SIDE1_NODES );
1205 RETCASE( SEW_BAD_SIDE2_NODES );
1207 return SMESH::SMESH_MeshEditor::SEW_OK;
1210 //=======================================================================
1211 //function : SewFreeBorders
1213 //=======================================================================
1215 SMESH::SMESH_MeshEditor::Sew_Error
1216 SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
1217 CORBA::Long SecondNodeID1,
1218 CORBA::Long LastNodeID1,
1219 CORBA::Long FirstNodeID2,
1220 CORBA::Long SecondNodeID2,
1221 CORBA::Long LastNodeID2,
1222 CORBA::Boolean CreatePolygons,
1223 CORBA::Boolean CreatePolyedrs)
1225 SMESHDS_Mesh* aMesh = GetMeshDS();
1227 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1228 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1229 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1230 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1231 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1232 const SMDS_MeshNode* aSide2ThirdNode = aMesh->FindNode( LastNodeID2 );
1234 if (!aBorderFirstNode ||
1235 !aBorderSecondNode||
1237 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1238 if (!aSide2FirstNode ||
1239 !aSide2SecondNode ||
1241 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1243 // Update Python script
1244 TCollection_AsciiString str ("error = mesh_editor.SewFreeBorders( ");
1245 str += TCollection_AsciiString( (int) FirstNodeID1 ) + ", ";
1246 str += TCollection_AsciiString( (int) SecondNodeID1 ) + ", ";
1247 str += TCollection_AsciiString( (int) LastNodeID1 ) + ", ";
1248 str += TCollection_AsciiString( (int) FirstNodeID2 ) + ", ";
1249 str += TCollection_AsciiString( (int) SecondNodeID2 ) + ", ";
1250 str += TCollection_AsciiString( (int) LastNodeID2 ) + ", ";
1251 str += TCollection_AsciiString( CreatePolygons ) + ", ";
1252 str += TCollection_AsciiString( CreatePolyedrs ) + ") ";
1253 addToPythonScript( str );
1255 ::SMESH_MeshEditor anEditor( _myMesh );
1256 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1267 //=======================================================================
1268 //function : SewConformFreeBorders
1270 //=======================================================================
1272 SMESH::SMESH_MeshEditor::Sew_Error
1273 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
1274 CORBA::Long SecondNodeID1,
1275 CORBA::Long LastNodeID1,
1276 CORBA::Long FirstNodeID2,
1277 CORBA::Long SecondNodeID2)
1279 SMESHDS_Mesh* aMesh = GetMeshDS();
1281 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeID1 );
1282 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1283 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeID1 );
1284 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeID2 );
1285 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( SecondNodeID2 );
1286 const SMDS_MeshNode* aSide2ThirdNode = 0;
1288 if (!aBorderFirstNode ||
1289 !aBorderSecondNode||
1291 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1292 if (!aSide2FirstNode ||
1294 return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1296 // Update Python script
1297 TCollection_AsciiString str ("error = mesh_editor.SewConformFreeBorders( ");
1298 str += TCollection_AsciiString( (int) FirstNodeID1 ) + ", ";
1299 str += TCollection_AsciiString( (int) SecondNodeID1 ) + ", ";
1300 str += TCollection_AsciiString( (int) LastNodeID1 ) + ", ";
1301 str += TCollection_AsciiString( (int) FirstNodeID2 ) + ", ";
1302 str += TCollection_AsciiString( (int) SecondNodeID2 ) + ")";
1303 addToPythonScript( str );
1305 ::SMESH_MeshEditor anEditor( _myMesh );
1306 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1316 //=======================================================================
1317 //function : SewBorderToSide
1319 //=======================================================================
1321 SMESH::SMESH_MeshEditor::Sew_Error
1322 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
1323 CORBA::Long SecondNodeIDOnFreeBorder,
1324 CORBA::Long LastNodeIDOnFreeBorder,
1325 CORBA::Long FirstNodeIDOnSide,
1326 CORBA::Long LastNodeIDOnSide,
1327 CORBA::Boolean CreatePolygons,
1328 CORBA::Boolean CreatePolyedrs)
1330 SMESHDS_Mesh* aMesh = GetMeshDS();
1332 const SMDS_MeshNode* aBorderFirstNode = aMesh->FindNode( FirstNodeIDOnFreeBorder );
1333 const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
1334 const SMDS_MeshNode* aBorderLastNode = aMesh->FindNode( LastNodeIDOnFreeBorder );
1335 const SMDS_MeshNode* aSide2FirstNode = aMesh->FindNode( FirstNodeIDOnSide );
1336 const SMDS_MeshNode* aSide2SecondNode = aMesh->FindNode( LastNodeIDOnSide );
1337 const SMDS_MeshNode* aSide2ThirdNode = 0;
1339 if (!aBorderFirstNode ||
1340 !aBorderSecondNode||
1342 return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1343 if (!aSide2FirstNode ||
1345 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
1347 // Update Python script
1348 TCollection_AsciiString str ("error = mesh_editor.SewBorderToSide( ");
1349 str += TCollection_AsciiString( (int) FirstNodeIDOnFreeBorder ) + ", ";
1350 str += TCollection_AsciiString( (int) SecondNodeIDOnFreeBorder ) + ", ";
1351 str += TCollection_AsciiString( (int) LastNodeIDOnFreeBorder ) + ", ";
1352 str += TCollection_AsciiString( (int) FirstNodeIDOnSide ) + ", ";
1353 str += TCollection_AsciiString( (int) LastNodeIDOnSide ) + ", ";
1354 str += TCollection_AsciiString( CreatePolygons ) + ", ";
1355 str += TCollection_AsciiString( CreatePolyedrs ) + ") ";
1356 addToPythonScript( str );
1358 ::SMESH_MeshEditor anEditor( _myMesh );
1359 return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1370 //=======================================================================
1371 //function : SewSideElements
1373 //=======================================================================
1375 SMESH::SMESH_MeshEditor::Sew_Error
1376 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
1377 const SMESH::long_array& IDsOfSide2Elements,
1378 CORBA::Long NodeID1OfSide1ToMerge,
1379 CORBA::Long NodeID1OfSide2ToMerge,
1380 CORBA::Long NodeID2OfSide1ToMerge,
1381 CORBA::Long NodeID2OfSide2ToMerge)
1383 SMESHDS_Mesh* aMesh = GetMeshDS();
1385 const SMDS_MeshNode* aFirstNode1ToMerge = aMesh->FindNode( NodeID1OfSide1ToMerge );
1386 const SMDS_MeshNode* aFirstNode2ToMerge = aMesh->FindNode( NodeID1OfSide2ToMerge );
1387 const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
1388 const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
1390 if (!aFirstNode1ToMerge ||
1391 !aFirstNode2ToMerge )
1392 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
1393 if (!aSecondNode1ToMerge||
1394 !aSecondNode2ToMerge)
1395 return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
1397 set<const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1398 for (int i = 0; i < IDsOfSide1Elements.length(); i++)
1400 CORBA::Long index = IDsOfSide1Elements[i];
1401 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1403 aSide1Elems.insert( elem );
1405 for (int i = 0; i < IDsOfSide2Elements.length(); i++)
1407 CORBA::Long index = IDsOfSide2Elements[i];
1408 const SMDS_MeshElement * elem = aMesh->FindElement(index);
1410 aSide2Elems.insert( elem );
1412 // Update Python script
1413 TCollection_AsciiString str ("error = mesh_editor.SewSideElements( ");
1414 addArray( str, IDsOfSide1Elements ) += ", ";
1415 addArray( str, IDsOfSide2Elements ) += ", ";
1416 str += TCollection_AsciiString( (int) NodeID1OfSide1ToMerge ) + ", ";
1417 str += TCollection_AsciiString( (int) NodeID1OfSide2ToMerge ) + ", ";
1418 str += TCollection_AsciiString( (int) NodeID2OfSide1ToMerge ) + ", ";
1419 str += TCollection_AsciiString( (int) NodeID2OfSide2ToMerge ) + ")";
1420 addToPythonScript( str );
1422 ::SMESH_MeshEditor anEditor( _myMesh );
1423 return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1426 aSecondNode1ToMerge,
1427 aSecondNode2ToMerge));