Salome HOME
Fix compilation warnings
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
1 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESH_MeshEditor_i.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESH_MeshEditor_i.hxx"
30
31 #include "SMDS_MeshEdge.hxx"
32 #include "SMDS_MeshFace.hxx"
33 #include "SMDS_MeshVolume.hxx"
34
35 #include "SMESH_MeshEditor.hxx"
36
37 #include "SMESH_Gen_i.hxx"
38 #include "SMESH_Filter_i.hxx"
39
40 #include "utilities.h"
41
42 #include <gp_Ax1.hxx>
43 #include <gp_Ax2.hxx>
44 #include <gp_Vec.hxx>
45
46 #include <sstream>
47
48 using namespace std;
49
50 //=======================================================================
51 //function : addAxis
52 //purpose  : 
53 //=======================================================================
54
55 static TCollection_AsciiString& addAxis(TCollection_AsciiString&  theStr,
56                                         const SMESH::AxisStruct & theAxis)
57 {
58   theStr += "SMESH.AxisStruct( ";
59   theStr += TCollection_AsciiString( theAxis.x  ) + ", ";
60   theStr += TCollection_AsciiString( theAxis.y  ) + ", ";
61   theStr += TCollection_AsciiString( theAxis.z  ) + ", ";
62   theStr += TCollection_AsciiString( theAxis.vx ) + ", ";
63   theStr += TCollection_AsciiString( theAxis.vy ) + ", ";
64   theStr += TCollection_AsciiString( theAxis.vz ) + " )";
65   return theStr;
66 }
67
68 //=============================================================================
69 /*!
70  *  
71  */
72 //=============================================================================
73
74 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh* theMesh)
75 {
76         _myMesh = theMesh;
77 };
78
79 //=============================================================================
80 /*!
81  *  
82  */
83 //=============================================================================
84
85 CORBA::Boolean
86   SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
87 {
88   ::SMESH_MeshEditor anEditor( _myMesh );
89   list< int > IdList;
90
91   for (int i = 0; i < IDsOfElements.length(); i++)
92     IdList.push_back( IDsOfElements[i] );
93
94   // Update Python script
95   TCollection_AsciiString str ("isDone = mesh_editor.RemoveElements(");
96   SMESH_Gen_i::AddArray( str, IDsOfElements ) += ")";
97   SMESH_Gen_i::AddToCurrentPyScript( str );
98 #ifdef _DEBUG_
99   SMESH_Gen_i::AddToCurrentPyScript( "print \"RemoveElements: \", isDone" );
100 #endif
101   // Remove Elements
102   return anEditor.Remove( IdList, false );
103 };
104
105 //=============================================================================
106 /*!
107  *  
108  */
109 //=============================================================================
110
111 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::
112         long_array & IDsOfNodes)
113 {
114   ::SMESH_MeshEditor anEditor( _myMesh );
115   list< int > IdList;
116   for (int i = 0; i < IDsOfNodes.length(); i++)
117     IdList.push_back( IDsOfNodes[i] );
118
119   // Update Python script
120   TCollection_AsciiString str ("isDone = mesh_editor.RemoveNodes(");
121   SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
122   SMESH_Gen_i::AddToCurrentPyScript( str );
123 #ifdef _DEBUG_
124   SMESH_Gen_i::AddToCurrentPyScript( "print \"RemoveNodes: \", isDone" );
125 #endif
126
127   return anEditor.Remove( IdList, true );
128 };
129
130 //=============================================================================
131 /*!
132  *  
133  */
134 //=============================================================================
135
136 CORBA::Boolean SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
137 {
138   int NbNodes = IDsOfNodes.length();
139   if (NbNodes == 2)
140   {
141     CORBA::Long index1 = IDsOfNodes[0];
142     CORBA::Long index2 = IDsOfNodes[1];
143     GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
144
145     // Update Python script
146     TCollection_AsciiString str ("isDone = mesh_editor.AddEdge([");
147     str += TCollection_AsciiString((int) index1) + ", ";
148     str += TCollection_AsciiString((int) index2) + " ])";
149     SMESH_Gen_i::AddToCurrentPyScript( str );
150   }
151   return true;
152 }
153
154 //=============================================================================
155 /*!
156  *  
157  */
158 //=============================================================================
159
160 CORBA::Boolean SMESH_MeshEditor_i::AddNode(CORBA::Double x,
161                                            CORBA::Double y, CORBA::Double z)
162 {
163   GetMeshDS()->AddNode(x, y, z);
164
165   // Update Python script
166   TCollection_AsciiString str ("isDone = mesh_editor.AddNode(");
167   str += TCollection_AsciiString( x ) + ", ";
168   str += TCollection_AsciiString( y ) + ", ";
169   str += TCollection_AsciiString( z ) + " )";
170   SMESH_Gen_i::AddToCurrentPyScript( str );
171
172   return true;
173 }
174
175 //=============================================================================
176 /*!
177  *  AddFace
178  */
179 //=============================================================================
180
181 CORBA::Boolean SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
182 {
183   int NbNodes = IDsOfNodes.length();
184   if (NbNodes < 3)
185   {
186     return false;
187   }
188
189   std::vector<const SMDS_MeshNode*> nodes (NbNodes);
190   for (int i = 0; i < NbNodes; i++)
191     nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
192
193   if (NbNodes == 3)
194   {
195     GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
196   }
197   else if (NbNodes == 4)
198   {
199     GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
200   }
201   else
202   {
203     GetMeshDS()->AddPolygonalFace(nodes);
204   }
205
206   // Update Python script
207   TCollection_AsciiString str ("isDone = mesh_editor.AddFace(");
208   SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
209   SMESH_Gen_i::AddToCurrentPyScript( str );
210 #ifdef _DEBUG_
211   SMESH_Gen_i::AddToCurrentPyScript( "print \"AddFace: \", isDone" );
212 #endif
213
214   return true;
215 };
216
217 //=============================================================================
218 /*!
219  *  
220  */
221 //=============================================================================
222
223 CORBA::Boolean SMESH_MeshEditor_i::AddVolume(const SMESH::
224                                              long_array & IDsOfNodes)
225 {
226   int NbNodes = IDsOfNodes.length();
227   vector< const SMDS_MeshNode*> n(NbNodes);
228   for(int i=0;i<NbNodes;i++)
229     n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
230
231   switch(NbNodes)
232   {
233   case 4:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
234   case 5:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
235   case 6:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
236   case 8:GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
237   }
238   // Update Python script
239   TCollection_AsciiString str ("isDone = mesh_editor.AddVolume(");
240   SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ")";
241   SMESH_Gen_i::AddToCurrentPyScript( str );
242 #ifdef _DEBUG_
243   SMESH_Gen_i::AddToCurrentPyScript( "print \"AddVolume: \", isDone" );
244 #endif
245   
246   return true;
247 };
248
249 //=============================================================================
250 /*!
251  *  AddPolyhedralVolume
252  */
253 //=============================================================================
254 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolume
255                                    (const SMESH::long_array & IDsOfNodes,
256                                     const SMESH::long_array & Quantities)
257 {
258   int NbNodes = IDsOfNodes.length();
259   std::vector<const SMDS_MeshNode*> n (NbNodes);
260   for (int i = 0; i < NbNodes; i++)
261     n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
262
263   int NbFaces = Quantities.length();
264   std::vector<int> q (NbFaces);
265   for (int j = 0; j < NbFaces; j++)
266     q[j] = Quantities[j];
267
268   GetMeshDS()->AddPolyhedralVolume(n, q);
269
270   // Update Python script
271   TCollection_AsciiString str ("isDone = mesh_editor.AddPolyhedralVolume(");
272   SMESH_Gen_i::AddArray( str, IDsOfNodes ) += ", ";
273   SMESH_Gen_i::AddArray( str, Quantities ) += ")";
274   SMESH_Gen_i::AddToCurrentPyScript( str );
275 #ifdef _DEBUG_
276   SMESH_Gen_i::AddToCurrentPyScript( "print \"AddPolyhedralVolume: \", isDone" );
277 #endif
278
279   return true;
280 };
281
282 //=============================================================================
283 /*!
284  *  AddPolyhedralVolumeByFaces
285  */
286 //=============================================================================
287 CORBA::Boolean SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
288                                    (const SMESH::long_array & IdsOfFaces)
289 {
290   int NbFaces = IdsOfFaces.length();
291   std::vector<const SMDS_MeshNode*> poly_nodes;
292   std::vector<int> quantities (NbFaces);
293
294   for (int i = 0; i < NbFaces; i++) {
295     const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
296     quantities[i] = aFace->NbNodes();
297
298     SMDS_ElemIteratorPtr It = aFace->nodesIterator();
299     while (It->more()) {
300       poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
301     }
302   }
303
304   GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
305
306   // Update Python script
307   TCollection_AsciiString str ("isDone = mesh_editor.AddPolyhedralVolumeByFaces(");
308   SMESH_Gen_i::AddArray( str, IdsOfFaces ) += ")";
309   SMESH_Gen_i::AddToCurrentPyScript( str );
310 #ifdef _DEBUG_
311   SMESH_Gen_i::AddToCurrentPyScript( "print \"AddPolyhedralVolume: \", isDone" );
312 #endif
313
314   return true;
315 };
316
317 //=============================================================================
318 /*!
319  *  
320  */
321 //=============================================================================
322
323 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long   NodeID,
324                                             CORBA::Double x,
325                                             CORBA::Double y,
326                                             CORBA::Double z)
327 {
328   const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
329   if ( !node )
330     return false;
331   
332   GetMeshDS()->MoveNode(node, x, y, z);
333
334   // Update Python script
335   TCollection_AsciiString str ("isDone = mesh_editor.MoveNode(");
336   str += TCollection_AsciiString((Standard_Integer) NodeID) + ", ";
337   str += TCollection_AsciiString((Standard_Real) x) + ", ";
338   str += TCollection_AsciiString((Standard_Real) y) + ", ";
339   str += TCollection_AsciiString((Standard_Real) z) + " )";
340   SMESH_Gen_i::AddToCurrentPyScript( str );
341
342   return true;
343 }
344
345 //=============================================================================
346 /*!
347  *  
348  */
349 //=============================================================================
350
351 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
352                                                CORBA::Long NodeID2)
353 {
354   const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
355   const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
356   if ( !n1 || !n2 )
357     return false;
358
359   // Update Python script
360   TCollection_AsciiString str ("isDone = mesh_editor.InverseDiag(");
361   str += TCollection_AsciiString((Standard_Integer) NodeID1) + ", ";
362   str += TCollection_AsciiString((Standard_Integer) NodeID2) + " )";
363   SMESH_Gen_i::AddToCurrentPyScript( str );
364
365   ::SMESH_MeshEditor aMeshEditor( _myMesh );
366   return aMeshEditor.InverseDiag ( n1, n2 );
367 }
368
369 //=============================================================================
370 /*!
371  *  
372  */
373 //=============================================================================
374
375 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
376                                               CORBA::Long NodeID2)
377 {
378   const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
379   const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
380   if ( !n1 || !n2 )
381     return false;
382
383   // Update Python script
384   TCollection_AsciiString str ("isDone = mesh_editor.DeleteDiag(");
385   str += TCollection_AsciiString((Standard_Integer) NodeID1) + ", ";
386   str += TCollection_AsciiString((Standard_Integer) NodeID2) + " )";
387   SMESH_Gen_i::AddToCurrentPyScript( str );
388
389   ::SMESH_MeshEditor aMeshEditor( _myMesh );
390   return aMeshEditor.DeleteDiag ( n1, n2 );
391 }
392
393 //=============================================================================
394 /*!
395  *  
396  */
397 //=============================================================================
398
399 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
400 {
401   ::SMESH_MeshEditor anEditor( _myMesh );
402   for (int i = 0; i < IDsOfElements.length(); i++)
403   {
404     CORBA::Long index = IDsOfElements[i];
405     const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
406     if ( elem )
407       anEditor.Reorient( elem );
408   }
409   // Update Python script
410   TCollection_AsciiString str ("isDone = mesh_editor.Reorient(");
411   SMESH_Gen_i::AddArray( str, IDsOfElements ) += ")";
412   SMESH_Gen_i::AddToCurrentPyScript( str );
413
414   return true;
415 }
416
417
418 //=============================================================================
419 /*!
420  *  
421  */
422 //=============================================================================
423
424 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
425 {
426   SMESH::long_array_var anElementsId = theObject->GetIDs();
427   CORBA::Boolean isDone = Reorient(anElementsId);
428
429   // Clear python line, created by Reorient()
430   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
431   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
432
433   // Update Python script
434   TCollection_AsciiString str ("isDone = mesh_editor.ReorientObject(");
435   SMESH_Gen_i::AddObject( str, theObject ) += ")";
436   SMESH_Gen_i::AddToCurrentPyScript( str );
437
438   return isDone;
439 }
440
441 //=============================================================================
442 /*!
443  *  
444  */
445 //=============================================================================
446
447 CORBA::Boolean
448   SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array &   IDsOfElements,
449                                  SMESH::NumericalFunctor_ptr Criterion,
450                                  CORBA::Double               MaxAngle)
451 {
452   set<const SMDS_MeshElement*> faces;
453   for (int i = 0; i < IDsOfElements.length(); i++)
454   {
455     CORBA::Long index = IDsOfElements[i];
456     const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
457     if ( elem && elem->GetType() == SMDSAbs_Face)
458       faces.insert( elem );
459   }
460   SMESH::NumericalFunctor_i* aNumericalFunctor = 
461     dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
462   SMESH::Controls::NumericalFunctorPtr aCrit;
463   if ( !aNumericalFunctor )
464     aCrit.reset( new SMESH::Controls::AspectRatio() );
465   else
466     aCrit = aNumericalFunctor->GetNumericalFunctor();
467
468   // Update Python script
469   TCollection_AsciiString str ("isDone = mesh_editor.TriToQuad(");
470   SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", None, ";
471   str += (Standard_Real) MaxAngle;
472   SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
473 #ifdef _DEBUG_
474   SMESH_Gen_i::AddToCurrentPyScript( "print \"TriToQuad: \", isDone" );
475 #endif
476
477   ::SMESH_MeshEditor anEditor( _myMesh );
478   return anEditor.TriToQuad( faces, aCrit, MaxAngle );
479 }
480
481 //=============================================================================
482 /*!
483  *  
484  */
485 //=============================================================================
486
487 CORBA::Boolean
488   SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr   theObject,
489                                        SMESH::NumericalFunctor_ptr Criterion,
490                                        CORBA::Double               MaxAngle)
491 {
492   SMESH::long_array_var anElementsId = theObject->GetIDs();
493   CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
494
495   // Clear python line(s), created by TriToQuad()
496   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
497   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
498 #ifdef _DEBUG_
499   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
500 #endif
501
502   // Update Python script
503   TCollection_AsciiString str ("isDone = mesh_editor.TriToQuadObject(");
504   SMESH_Gen_i::AddObject( str, theObject ) += ", None, ";
505   str += (Standard_Real) MaxAngle;
506   SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
507 #ifdef _DEBUG_
508   SMESH_Gen_i::AddToCurrentPyScript( "print \"TriToQuadObject: \", isDone" );
509 #endif
510
511   return isDone;
512 }
513
514 //=============================================================================
515 /*!
516  *  
517  */
518 //=============================================================================
519
520 CORBA::Boolean
521   SMESH_MeshEditor_i::QuadToTri(const SMESH::long_array &   IDsOfElements,
522                                 SMESH::NumericalFunctor_ptr Criterion)
523 {
524   set<const SMDS_MeshElement*> faces;
525   for (int i = 0; i < IDsOfElements.length(); i++)
526   {
527     CORBA::Long index = IDsOfElements[i];
528     const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
529     if ( elem && elem->GetType() == SMDSAbs_Face)
530       faces.insert( elem );
531   }
532   SMESH::NumericalFunctor_i* aNumericalFunctor = 
533     dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
534   SMESH::Controls::NumericalFunctorPtr aCrit;
535   if ( !aNumericalFunctor )
536     aCrit.reset( new SMESH::Controls::AspectRatio() );
537   else
538     aCrit = aNumericalFunctor->GetNumericalFunctor();
539
540
541   // Update Python script
542   TCollection_AsciiString str ("isDone = mesh_editor.QuadToTri(");
543   SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", None ), ";
544   SMESH_Gen_i::AddToCurrentPyScript( str );
545 #ifdef _DEBUG_
546   SMESH_Gen_i::AddToCurrentPyScript( "print \"QuadToTri: \", isDone" );
547 #endif
548
549   ::SMESH_MeshEditor anEditor( _myMesh );
550   return anEditor.QuadToTri( faces, aCrit );
551 }
552
553 //=============================================================================
554 /*!
555  *  
556  */
557 //=============================================================================
558
559 CORBA::Boolean
560   SMESH_MeshEditor_i::SplitQuad(const SMESH::long_array & IDsOfElements,
561                                 CORBA::Boolean            Diag13)
562 {
563   set<const SMDS_MeshElement*> faces;
564   for (int i = 0; i < IDsOfElements.length(); i++)
565   {
566     CORBA::Long index = IDsOfElements[i];
567     const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
568     if ( elem && elem->GetType() == SMDSAbs_Face)
569       faces.insert( elem );
570   }
571
572   // Update Python script
573   TCollection_AsciiString str ("isDone = mesh_editor.SplitQuad(");
574   SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", ";
575   str += TCollection_AsciiString( Diag13 );
576   SMESH_Gen_i::AddToCurrentPyScript( str + ")" );
577 #ifdef _DEBUG_
578   SMESH_Gen_i::AddToCurrentPyScript( "print \"SplitQuad: \", isDone" );
579 #endif
580
581   ::SMESH_MeshEditor anEditor( _myMesh );
582   return anEditor.QuadToTri( faces, Diag13 );
583 }
584
585 //=============================================================================
586 /*!
587  *  
588  */
589 //=============================================================================
590
591 CORBA::Boolean
592   SMESH_MeshEditor_i::SplitQuadObject(SMESH::SMESH_IDSource_ptr theObject,
593                                       CORBA::Boolean            Diag13)
594 {
595   SMESH::long_array_var anElementsId = theObject->GetIDs();
596   CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
597
598   // Clear python line(s), created by SplitQuad()
599   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
600   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
601 #ifdef _DEBUG_
602   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
603 #endif
604
605   // Update Python script
606   TCollection_AsciiString str ("isDone = mesh_editor.SplitQuadObject(");
607   SMESH_Gen_i::AddObject( str, theObject ) += ", ";
608   str += TCollection_AsciiString( Diag13 ) + ")";
609   SMESH_Gen_i::AddToCurrentPyScript( str );
610 #ifdef _DEBUG_
611   SMESH_Gen_i::AddToCurrentPyScript( "print \"SplitQuadObject: \", isDone" );
612 #endif
613
614   return isDone;
615 }
616
617 //=======================================================================
618 //function : Smooth
619 //purpose  : 
620 //=======================================================================
621
622 CORBA::Boolean
623   SMESH_MeshEditor_i::Smooth(const SMESH::long_array &              IDsOfElements,
624                              const SMESH::long_array &              IDsOfFixedNodes,
625                              CORBA::Long                            MaxNbOfIterations,
626                              CORBA::Double                          MaxAspectRatio,
627                              SMESH::SMESH_MeshEditor::Smooth_Method Method)
628 {
629   return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
630                 MaxAspectRatio, Method, false );
631 }
632
633 //=======================================================================
634 //function : SmoothParametric
635 //purpose  : 
636 //=======================================================================
637
638 CORBA::Boolean
639   SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array &              IDsOfElements,
640                                        const SMESH::long_array &              IDsOfFixedNodes,
641                                        CORBA::Long                            MaxNbOfIterations,
642                                        CORBA::Double                          MaxAspectRatio,
643                                        SMESH::SMESH_MeshEditor::Smooth_Method Method)
644 {
645   return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
646                 MaxAspectRatio, Method, true );
647 }
648
649 //=======================================================================
650 //function : SmoothObject
651 //purpose  : 
652 //=======================================================================
653
654 CORBA::Boolean
655   SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr              theObject,
656                                    const SMESH::long_array &              IDsOfFixedNodes,
657                                    CORBA::Long                            MaxNbOfIterations,
658                                    CORBA::Double                          MaxAspectRatio,
659                                    SMESH::SMESH_MeshEditor::Smooth_Method Method)
660 {
661   return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
662                        MaxAspectRatio, Method, false);
663 }
664
665 //=======================================================================
666 //function : SmoothParametricObject
667 //purpose  : 
668 //=======================================================================
669
670 CORBA::Boolean
671   SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr              theObject,
672                                    const SMESH::long_array &              IDsOfFixedNodes,
673                                    CORBA::Long                            MaxNbOfIterations,
674                                    CORBA::Double                          MaxAspectRatio,
675                                    SMESH::SMESH_MeshEditor::Smooth_Method Method)
676 {
677   return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
678                        MaxAspectRatio, Method, true);
679 }
680
681 //=============================================================================
682 /*!
683  *  
684  */
685 //=============================================================================
686
687 CORBA::Boolean
688   SMESH_MeshEditor_i::smooth(const SMESH::long_array &              IDsOfElements,
689                              const SMESH::long_array &              IDsOfFixedNodes,
690                              CORBA::Long                            MaxNbOfIterations,
691                              CORBA::Double                          MaxAspectRatio,
692                              SMESH::SMESH_MeshEditor::Smooth_Method Method,
693                              bool                                   IsParametric)
694 {
695   SMESHDS_Mesh* aMesh = GetMeshDS();
696
697   set<const SMDS_MeshElement*> elements;
698   for (int i = 0; i < IDsOfElements.length(); i++)
699   {
700     CORBA::Long index = IDsOfElements[i];
701     const SMDS_MeshElement * elem = aMesh->FindElement(index);
702     if ( elem && elem->GetType() == SMDSAbs_Face)
703       elements.insert( elem );
704   }
705
706   set<const SMDS_MeshNode*> fixedNodes;
707   for (int i = 0; i < IDsOfFixedNodes.length(); i++)
708   {
709     CORBA::Long index = IDsOfFixedNodes[i];
710     const SMDS_MeshNode * node = aMesh->FindNode(index);
711     if ( node )
712       fixedNodes.insert( node );
713   }
714   ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
715   if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
716     method = ::SMESH_MeshEditor::CENTROIDAL;
717
718   ::SMESH_MeshEditor anEditor( _myMesh );
719   anEditor.Smooth(elements, fixedNodes, method,
720                   MaxNbOfIterations, MaxAspectRatio, IsParametric );
721
722   // Update Python script
723   TCollection_AsciiString str ("isDone = mesh_editor.");
724   str += (char*) (IsParametric ? "SmoothParametric( " : "Smooth( ");
725   SMESH_Gen_i::AddArray( str, IDsOfElements ) += ", ";
726   SMESH_Gen_i::AddArray( str, IDsOfFixedNodes ) += ", ";
727   str += (Standard_Integer) MaxNbOfIterations;
728   str += ", ";
729   str += (Standard_Real) MaxAspectRatio;
730   if ( method == ::SMESH_MeshEditor::CENTROIDAL )
731     str += ", SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH, ";
732   else
733     str += ", SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH, ";
734   str += IsParametric;
735   str += " )";
736   SMESH_Gen_i::AddToCurrentPyScript( str );
737 #ifdef _DEBUG_
738   SMESH_Gen_i::AddToCurrentPyScript( "print \"Smooth: \", isDone" );
739 #endif
740
741   return true;
742 }
743
744 //=============================================================================
745 /*!
746  *  
747  */
748 //=============================================================================
749
750 CORBA::Boolean
751   SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr              theObject,
752                                    const SMESH::long_array &              IDsOfFixedNodes,
753                                    CORBA::Long                            MaxNbOfIterations,
754                                    CORBA::Double                          MaxAspectRatio,
755                                    SMESH::SMESH_MeshEditor::Smooth_Method Method,
756                                    bool                                   IsParametric)
757 {
758   SMESH::long_array_var anElementsId = theObject->GetIDs();
759   CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
760                                   MaxAspectRatio, Method, IsParametric);
761
762   // Clear python line(s), created by Smooth()
763   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
764   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
765 #ifdef _DEBUG_
766   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
767 #endif
768
769   // Update Python script
770   TCollection_AsciiString str ("isDone = mesh_editor.");
771   str += (char*) (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ");
772   SMESH_Gen_i::AddObject( str, theObject ) += ", ";
773   SMESH_Gen_i::AddArray( str, IDsOfFixedNodes ) += ", ";
774   str += (Standard_Integer) MaxNbOfIterations;
775   str += ", ";
776   str += (Standard_Real) MaxAspectRatio;
777   if ( Method == ::SMESH_MeshEditor::CENTROIDAL )
778     str += ", SMESH.SMESH_MeshEditor.CENTROIDAL_SMOOTH, ";
779   else
780     str += ", SMESH.SMESH_MeshEditor.LAPLACIAN_SMOOTH, ";
781   str += IsParametric;
782   str += " )";
783   SMESH_Gen_i::AddToCurrentPyScript( str );
784 #ifdef _DEBUG_
785   SMESH_Gen_i::AddToCurrentPyScript( "print \"SmoothObject: \", isDone" );
786 #endif
787
788   return isDone;
789 }
790
791 //=============================================================================
792 /*!
793  *  
794  */
795 //=============================================================================
796
797 void SMESH_MeshEditor_i::RenumberNodes()
798 {
799   // Update Python script
800   SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.RenumberNodes()" );
801
802   GetMeshDS()->Renumber( true );
803 }
804
805 //=============================================================================
806 /*!
807  *  
808  */
809 //=============================================================================
810
811 void SMESH_MeshEditor_i::RenumberElements()
812 {
813   // Update Python script
814   SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.RenumberElements()" );
815
816   GetMeshDS()->Renumber( false );
817 }
818
819 //=======================================================================
820 //function : RotationSweep
821 //purpose  : 
822 //=======================================================================
823
824 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
825                                        const SMESH::AxisStruct & theAxis,
826                                        CORBA::Double             theAngleInRadians,
827                                        CORBA::Long               theNbOfSteps,
828                                        CORBA::Double             theTolerance)
829 {
830   SMESHDS_Mesh* aMesh = GetMeshDS();
831
832   set<const SMDS_MeshElement*> elements;
833   for (int i = 0; i < theIDsOfElements.length(); i++)
834   {
835     CORBA::Long index = theIDsOfElements[i];
836     const SMDS_MeshElement * elem = aMesh->FindElement(index);
837     if ( elem )
838       elements.insert( elem );
839   }
840   gp_Ax1 Ax1 (gp_Pnt( theAxis.x, theAxis.y, theAxis.z ),
841               gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
842
843   ::SMESH_MeshEditor anEditor( _myMesh );
844   anEditor.RotationSweep (elements, Ax1, theAngleInRadians,
845                           theNbOfSteps, theTolerance);
846
847   // Update Python script
848   TCollection_AsciiString str = "axis = ";
849   addAxis( str, theAxis );
850   SMESH_Gen_i::AddToCurrentPyScript( str );
851   str = "mesh_editor.RotationSweep(";
852   SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", axis, ";
853   str += TCollection_AsciiString( theAngleInRadians ) + ", ";
854   str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
855   str += TCollection_AsciiString( theTolerance      ) + " )";
856   SMESH_Gen_i::AddToCurrentPyScript( str );
857 }
858
859 //=======================================================================
860 //function : RotationSweepObject
861 //purpose  : 
862 //=======================================================================
863
864 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
865                                              const SMESH::AxisStruct & theAxis,
866                                              CORBA::Double             theAngleInRadians,
867                                              CORBA::Long               theNbOfSteps,
868                                              CORBA::Double             theTolerance)
869 {
870   SMESH::long_array_var anElementsId = theObject->GetIDs();
871   RotationSweep(anElementsId, theAxis, theAngleInRadians, theNbOfSteps, theTolerance);
872
873   // Clear python line, created by RotationSweep()
874   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
875   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
876
877   // Update Python script
878   TCollection_AsciiString str ("mesh_editor.RotationSweepObject(");
879   SMESH_Gen_i::AddObject( str, theObject ) += ", axis, ";
880   str += TCollection_AsciiString( theAngleInRadians ) + ", ";
881   str += TCollection_AsciiString( (int)theNbOfSteps ) + ", ";
882   str += TCollection_AsciiString( theTolerance      ) + " )";
883   SMESH_Gen_i::AddToCurrentPyScript( str );
884 }
885
886 //=======================================================================
887 //function : ExtrusionSweep
888 //purpose  : 
889 //=======================================================================
890
891 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
892                                         const SMESH::DirStruct &  theStepVector,
893                                         CORBA::Long               theNbOfSteps)
894 {
895   SMESHDS_Mesh* aMesh = GetMeshDS();
896
897   set<const SMDS_MeshElement*> elements;
898   for (int i = 0; i < theIDsOfElements.length(); i++)
899   {
900     CORBA::Long index = theIDsOfElements[i];
901     const SMDS_MeshElement * elem = aMesh->FindElement(index);
902     if ( elem )
903       elements.insert( elem );
904   }
905   const SMESH::PointStruct * P = &theStepVector.PS;
906   gp_Vec stepVec( P->x, P->y, P->z );
907
908   ::SMESH_MeshEditor anEditor( _myMesh );
909   anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
910
911   // Update Python script
912   TCollection_AsciiString str = "stepVector = SMESH.DirStruct( SMESH.PointStruct ( ";
913   str += (TCollection_AsciiString) stepVec.X() + ", ";
914   str += (TCollection_AsciiString) stepVec.Y() + ", ";
915   str += (TCollection_AsciiString) stepVec.Z() + " ))";
916   SMESH_Gen_i::AddToCurrentPyScript( str );
917   str = ("mesh_editor.ExtrusionSweep(");
918   SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", stepVector, ";
919   str += TCollection_AsciiString((int)theNbOfSteps) + " )";
920   SMESH_Gen_i::AddToCurrentPyScript( str );
921 }
922
923
924 //=======================================================================
925 //function : ExtrusionSweepObject
926 //purpose  : 
927 //=======================================================================
928
929 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
930                                               const SMESH::DirStruct &  theStepVector,
931                                               CORBA::Long               theNbOfSteps)
932 {
933   SMESH::long_array_var anElementsId = theObject->GetIDs();
934   ExtrusionSweep(anElementsId, theStepVector, theNbOfSteps);
935
936   // Clear python line, created by ExtrusionSweep()
937   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
938   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
939
940   // Update Python script
941   TCollection_AsciiString str ("mesh_editor.ExtrusionSweepObject(");
942   SMESH_Gen_i::AddObject( str, theObject ) += ", stepVector, ";
943   str += TCollection_AsciiString((int)theNbOfSteps) + " )";
944   SMESH_Gen_i::AddToCurrentPyScript( str );
945 }
946 //=======================================================================
947 //function : ExtrusionSweepObject1D
948 //purpose  : 
949 //=======================================================================
950
951 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
952                                                 const SMESH::DirStruct &  theStepVector,
953                                                 CORBA::Long               theNbOfSteps)
954 {
955   SMESHDS_Mesh* aMesh = GetMeshDS();
956
957   SMESH::long_array_var allElementsId = theObject->GetIDs();
958
959   set<const SMDS_MeshElement*> elements;
960   for (int i = 0; i < allElementsId->length(); i++)
961   {
962     CORBA::Long index = allElementsId[i];
963     const SMDS_MeshElement * elem = aMesh->FindElement(index);
964     if ( elem && elem->GetType() == SMDSAbs_Edge )
965       elements.insert( elem );
966   }
967   const SMESH::PointStruct * P = &theStepVector.PS;
968   gp_Vec stepVec( P->x, P->y, P->z );
969
970   ::SMESH_MeshEditor anEditor( _myMesh );
971   anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
972 }
973
974 //=======================================================================
975 //function : ExtrusionSweepObject2D
976 //purpose  : 
977 //=======================================================================
978
979 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
980                                                 const SMESH::DirStruct &  theStepVector,
981                                                 CORBA::Long               theNbOfSteps)
982 {
983   SMESHDS_Mesh* aMesh = GetMeshDS();
984
985   SMESH::long_array_var allElementsId = theObject->GetIDs();
986
987   set<const SMDS_MeshElement*> elements;
988   for (int i = 0; i < allElementsId->length(); i++)
989   {
990     CORBA::Long index = allElementsId[i];
991     const SMDS_MeshElement * elem = aMesh->FindElement(index);
992     if ( elem && elem->GetType() == SMDSAbs_Face )
993       elements.insert( elem );
994   }
995   const SMESH::PointStruct * P = &theStepVector.PS;
996   gp_Vec stepVec( P->x, P->y, P->z );
997
998   ::SMESH_MeshEditor anEditor( _myMesh );
999   anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps);
1000 }
1001
1002 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1003
1004 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1005 {
1006   switch ( e ) {
1007   RETCASE( EXTR_OK );
1008   RETCASE( EXTR_NO_ELEMENTS );
1009   RETCASE( EXTR_PATH_NOT_EDGE );
1010   RETCASE( EXTR_BAD_PATH_SHAPE );
1011   RETCASE( EXTR_BAD_STARTING_NODE );
1012   RETCASE( EXTR_BAD_ANGLES_NUMBER );
1013   RETCASE( EXTR_CANT_GET_TANGENT );
1014   }
1015   return SMESH::SMESH_MeshEditor::EXTR_OK;
1016 }
1017
1018 //=======================================================================
1019 //function : ExtrusionAlongPath
1020 //purpose  : 
1021 //=======================================================================
1022
1023 SMESH::SMESH_MeshEditor::Extrusion_Error
1024   SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array &   theIDsOfElements,
1025                                          SMESH::SMESH_Mesh_ptr       thePathMesh,
1026                                          GEOM::GEOM_Object_ptr       thePathShape,
1027                                          CORBA::Long                 theNodeStart,
1028                                          CORBA::Boolean              theHasAngles,
1029                                          const SMESH::double_array & theAngles,
1030                                          CORBA::Boolean              theHasRefPoint,
1031                                          const SMESH::PointStruct &  theRefPoint)
1032 {
1033   SMESHDS_Mesh*  aMesh = GetMeshDS();
1034
1035   if ( thePathMesh->_is_nil() || thePathShape->_is_nil() )
1036     return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1037
1038   SMESH_Mesh_i* aMeshImp = dynamic_cast<SMESH_Mesh_i*>( SMESH_Gen_i::GetServant( thePathMesh ).in() );
1039   TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1040   SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1041
1042   if ( !aSubMesh )
1043     return SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1044
1045   SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1046   if ( !nodeStart )
1047     return SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1048
1049   set<const SMDS_MeshElement*> elements;
1050   for (int i = 0; i < theIDsOfElements.length(); i++)
1051   {
1052     CORBA::Long index = theIDsOfElements[i];
1053     const SMDS_MeshElement * elem = aMesh->FindElement(index);
1054     if ( elem )
1055       elements.insert( elem );
1056   }
1057
1058   list<double> angles;
1059   for (int i = 0; i < theAngles.length(); i++)
1060   {
1061     angles.push_back( theAngles[i] );
1062   }
1063
1064   gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1065
1066   // Update Python script
1067   TCollection_AsciiString str = "refPoint = SMESH.PointStruct( ";
1068   str += (TCollection_AsciiString) refPnt.X() + ", ";
1069   str += (TCollection_AsciiString) refPnt.Y() + ", ";
1070   str += (TCollection_AsciiString) refPnt.Z() + " )";
1071   SMESH_Gen_i::AddToCurrentPyScript( str );
1072   str = ("error = mesh_editor.ExtrusionAlongPath(");
1073   SMESH_Gen_i::AddArray ( str, theIDsOfElements ) += ", ";
1074   SMESH_Gen_i::AddObject( str, thePathMesh ) += ", ";
1075   SMESH_Gen_i::AddObject( str, thePathShape ) += ", ";
1076   str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
1077   str += TCollection_AsciiString( (int)theHasAngles ) + ", ";
1078   SMESH_Gen_i::AddArray ( str, theAngles ) += ", ";
1079   str += (TCollection_AsciiString) theHasRefPoint + ", refPoint )";
1080   SMESH_Gen_i::AddToCurrentPyScript( str );
1081
1082   ::SMESH_MeshEditor anEditor( _myMesh );
1083   return convExtrError( anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart, theHasAngles, angles, theHasRefPoint, refPnt ) );
1084 }
1085
1086 //=======================================================================
1087 //function : ExtrusionAlongPathObject
1088 //purpose  : 
1089 //=======================================================================
1090
1091 SMESH::SMESH_MeshEditor::Extrusion_Error
1092   SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr   theObject,
1093                                                SMESH::SMESH_Mesh_ptr       thePathMesh,
1094                                                GEOM::GEOM_Object_ptr       thePathShape,
1095                                                CORBA::Long                 theNodeStart,
1096                                                CORBA::Boolean              theHasAngles,
1097                                                const SMESH::double_array & theAngles,
1098                                                CORBA::Boolean              theHasRefPoint,
1099                                                const SMESH::PointStruct &  theRefPoint)
1100 {
1101   SMESH::long_array_var anElementsId = theObject->GetIDs();
1102   SMESH::SMESH_MeshEditor::Extrusion_Error error = ExtrusionAlongPath
1103     (anElementsId, thePathMesh, thePathShape, theNodeStart,
1104      theHasAngles, theAngles, theHasRefPoint, theRefPoint);
1105
1106   // Clear python line, created by ExtrusionAlongPath()
1107   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1108   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1109
1110   // Update Python script
1111   TCollection_AsciiString str ("error = mesh_editor.ExtrusionAlongPathObject(");
1112   SMESH_Gen_i::AddObject( str, theObject ) += ", ";
1113   SMESH_Gen_i::AddObject( str, thePathMesh ) += ", ";
1114   SMESH_Gen_i::AddObject( str, thePathShape ) += ", ";
1115   str += TCollection_AsciiString( (int)theNodeStart ) + ", ";
1116   str += TCollection_AsciiString( theHasAngles ) + ", ";
1117   SMESH_Gen_i::AddArray ( str, theAngles ) += ", ";
1118   str += TCollection_AsciiString( theHasRefPoint ) + ", refPoint )";
1119   SMESH_Gen_i::AddToCurrentPyScript( str );
1120
1121   return error;
1122 }
1123
1124 //=======================================================================
1125 //function : Mirror
1126 //purpose  : 
1127 //=======================================================================
1128
1129 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElements,
1130                                 const SMESH::AxisStruct &           theAxis,
1131                                 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1132                                 CORBA::Boolean                      theCopy)
1133 {
1134   SMESHDS_Mesh* aMesh = GetMeshDS();
1135
1136   set<const SMDS_MeshElement*> elements;
1137   for (int i = 0; i < theIDsOfElements.length(); i++)
1138   {
1139     CORBA::Long index = theIDsOfElements[i];
1140     const SMDS_MeshElement * elem = aMesh->FindElement(index);
1141     if ( elem )
1142       elements.insert( elem );
1143   }
1144   gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1145   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1146
1147   gp_Trsf aTrsf;
1148   TCollection_AsciiString typeStr, copyStr( theCopy );
1149   switch ( theMirrorType ) {
1150   case  SMESH::SMESH_MeshEditor::POINT:
1151     aTrsf.SetMirror( P );
1152     typeStr = "SMESH.SMESH_MeshEditor.POINT";
1153     break;
1154   case  SMESH::SMESH_MeshEditor::AXIS:
1155     aTrsf.SetMirror( gp_Ax1( P, V ));
1156     typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1157     break;
1158   default:
1159     aTrsf.SetMirror( gp_Ax2( P, V ));
1160     typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1161   }
1162
1163   // Update Python script
1164   TCollection_AsciiString str ("mesh_editor.Mirror(");
1165   SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", ";
1166   addAxis( str, theAxis )           += ", ";
1167   str += typeStr                     + ", ";
1168   str += copyStr                     + " )";
1169   SMESH_Gen_i::AddToCurrentPyScript( str );
1170
1171   ::SMESH_MeshEditor anEditor( _myMesh );
1172   anEditor.Transform (elements, aTrsf, theCopy);
1173 }
1174
1175 //=======================================================================
1176 //function : MirrorObject
1177 //purpose  : 
1178 //=======================================================================
1179
1180 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr           theObject,
1181                                       const SMESH::AxisStruct &           theAxis,
1182                                       SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
1183                                       CORBA::Boolean                      theCopy)
1184 {
1185   SMESH::long_array_var anElementsId = theObject->GetIDs();
1186   Mirror(anElementsId, theAxis, theMirrorType, theCopy);
1187
1188   // Clear python line, created by Mirror()
1189   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1190   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1191
1192   // Update Python script
1193   TCollection_AsciiString typeStr, copyStr( theCopy );
1194   switch ( theMirrorType ) {
1195   case  SMESH::SMESH_MeshEditor::POINT:
1196     typeStr = "SMESH.SMESH_MeshEditor.POINT";
1197     break;
1198   case  SMESH::SMESH_MeshEditor::AXIS:
1199     typeStr = "SMESH.SMESH_MeshEditor.AXIS";
1200     break;
1201   default:
1202     typeStr = "SMESH.SMESH_MeshEditor.PLANE";
1203   }
1204
1205   TCollection_AsciiString str ("mesh_editor.MirrorObject(");
1206   SMESH_Gen_i::AddObject( str, theObject ) += ", ";
1207   addAxis( str, theAxis ) += ", ";
1208   str += typeStr + ", " + copyStr + " )";
1209   SMESH_Gen_i::AddToCurrentPyScript( str );
1210 }
1211
1212 //=======================================================================
1213 //function : Translate
1214 //purpose  : 
1215 //=======================================================================
1216
1217 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
1218                                    const SMESH::DirStruct &  theVector,
1219                                    CORBA::Boolean            theCopy)
1220 {
1221   SMESHDS_Mesh* aMesh = GetMeshDS();
1222
1223   set<const SMDS_MeshElement*> elements;
1224   for (int i = 0; i < theIDsOfElements.length(); i++)
1225   {
1226     CORBA::Long index = theIDsOfElements[i];
1227     const SMDS_MeshElement * elem = aMesh->FindElement(index);
1228     if ( elem )
1229       elements.insert( elem );
1230   }
1231   gp_Trsf aTrsf;
1232   const SMESH::PointStruct * P = &theVector.PS;
1233   aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
1234
1235   ::SMESH_MeshEditor anEditor( _myMesh );
1236   anEditor.Transform (elements, aTrsf, theCopy);
1237
1238   // Update Python script
1239   TCollection_AsciiString str = "vector = SMESH.DirStruct( SMESH.PointStruct ( ";
1240   str += (TCollection_AsciiString) P->x + ", ";
1241   str += (TCollection_AsciiString) P->y + ", ";
1242   str += (TCollection_AsciiString) P->z + " ))";
1243   SMESH_Gen_i::AddToCurrentPyScript( str );
1244   str = ("mesh_editor.Translate(");
1245   SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", vector, ";
1246   str += (TCollection_AsciiString) theCopy + " )";
1247   SMESH_Gen_i::AddToCurrentPyScript( str );
1248 }
1249
1250 //=======================================================================
1251 //function : TranslateObject
1252 //purpose  : 
1253 //=======================================================================
1254
1255 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
1256                                          const SMESH::DirStruct &  theVector,
1257                                          CORBA::Boolean            theCopy)
1258 {
1259   SMESH::long_array_var anElementsId = theObject->GetIDs();
1260   Translate(anElementsId, theVector, theCopy);
1261
1262   // Clear python line, created by Translate()
1263   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1264   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1265
1266   // Update Python script
1267   TCollection_AsciiString str ("mesh_editor.TranslateObject(");
1268   SMESH_Gen_i::AddObject( str, theObject ) += ", vector, ";
1269   str += TCollection_AsciiString( theCopy ) + " )";
1270   SMESH_Gen_i::AddToCurrentPyScript( str );
1271 }
1272
1273 //=======================================================================
1274 //function : Rotate
1275 //purpose  : 
1276 //=======================================================================
1277
1278 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
1279                                 const SMESH::AxisStruct & theAxis,
1280                                 CORBA::Double             theAngle,
1281                                 CORBA::Boolean            theCopy)
1282 {
1283   SMESHDS_Mesh* aMesh = GetMeshDS();
1284
1285   set<const SMDS_MeshElement*> elements;
1286   for (int i = 0; i < theIDsOfElements.length(); i++)
1287   {
1288     CORBA::Long index = theIDsOfElements[i];
1289     const SMDS_MeshElement * elem = aMesh->FindElement(index);
1290     if ( elem )
1291       elements.insert( elem );
1292   }
1293   gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
1294   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
1295
1296   gp_Trsf aTrsf;
1297   aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
1298   
1299   ::SMESH_MeshEditor anEditor( _myMesh );
1300   anEditor.Transform (elements, aTrsf, theCopy);
1301
1302   // Update Python script
1303   TCollection_AsciiString str ("axis = ");
1304   addAxis( str, theAxis );
1305   SMESH_Gen_i::AddToCurrentPyScript( str );
1306   str = ("mesh_editor.Rotate(");
1307   SMESH_Gen_i::AddArray( str, theIDsOfElements ) += ", axis, ";
1308   str += (TCollection_AsciiString) theAngle + ", ";
1309   str += (TCollection_AsciiString) theCopy + " )";
1310   SMESH_Gen_i::AddToCurrentPyScript( str );
1311 }
1312
1313 //=======================================================================
1314 //function : RotateObject
1315 //purpose  : 
1316 //=======================================================================
1317
1318 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
1319                                       const SMESH::AxisStruct & theAxis,
1320                                       CORBA::Double             theAngle,
1321                                       CORBA::Boolean            theCopy)
1322 {
1323   SMESH::long_array_var anElementsId = theObject->GetIDs();
1324   Rotate(anElementsId, theAxis, theAngle, theCopy);
1325
1326   // Clear python line, created by Rotate()
1327   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1328   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1329
1330   // Update Python script
1331   TCollection_AsciiString str ("mesh_editor.RotateObject(");
1332   SMESH_Gen_i::AddObject( str, theObject ) += ", axis, ";
1333   str += TCollection_AsciiString( theAngle ) + ", ";
1334   str += TCollection_AsciiString( theCopy ) + " )";
1335   SMESH_Gen_i::AddToCurrentPyScript( str );
1336 }
1337
1338 //=======================================================================
1339 //function : FindCoincidentNodes
1340 //purpose  : 
1341 //=======================================================================
1342
1343 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double                  Tolerance,
1344                                               SMESH::array_of_long_array_out GroupsOfNodes)
1345 {
1346   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1347   ::SMESH_MeshEditor anEditor( _myMesh );
1348   set<const SMDS_MeshNode*> nodes; // no input nodes
1349   anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
1350
1351   GroupsOfNodes = new SMESH::array_of_long_array;
1352   GroupsOfNodes->length( aListOfListOfNodes.size() );
1353   ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
1354   for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ )
1355   {
1356     list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
1357     list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
1358     SMESH::long_array& aGroup = GroupsOfNodes[ i ];
1359     aGroup.length( aListOfNodes.size() );
1360     for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
1361       aGroup[ j ] = (*lIt)->GetID();
1362   }
1363 }
1364
1365 //=======================================================================
1366 //function : MergeNodes
1367 //purpose  : 
1368 //=======================================================================
1369
1370 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
1371 {
1372   SMESHDS_Mesh* aMesh = GetMeshDS();
1373
1374   TCollection_AsciiString str( "mesh_editor.MergeNodes([" );
1375   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
1376   for (int i = 0; i < GroupsOfNodes.length(); i++)
1377   {
1378     const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
1379     aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
1380     list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
1381     for ( int j = 0; j < aNodeGroup.length(); j++ )
1382     {
1383       CORBA::Long index = aNodeGroup[ j ];
1384       const SMDS_MeshNode * node = aMesh->FindNode(index);
1385       if ( node )
1386         aListOfNodes.push_back( node );
1387     }
1388     if ( aListOfNodes.size() < 2 )
1389       aListOfListOfNodes.pop_back();
1390
1391     if ( i > 0 )
1392       str += ",";
1393     SMESH_Gen_i::AddArray( str, aNodeGroup );
1394   }
1395   ::SMESH_MeshEditor anEditor( _myMesh );
1396   anEditor.MergeNodes( aListOfListOfNodes );
1397
1398   // Update Python script
1399   SMESH_Gen_i::AddToCurrentPyScript( str + "])" );
1400 }
1401
1402 //=======================================================================
1403 //function : MergeEqualElements
1404 //purpose  : 
1405 //=======================================================================
1406
1407 void SMESH_MeshEditor_i::MergeEqualElements()
1408 {
1409   ::SMESH_MeshEditor anEditor( _myMesh );
1410   anEditor.MergeEqualElements();
1411
1412   // Update Python script
1413   SMESH_Gen_i::AddToCurrentPyScript( "mesh_editor.MergeEqualElements()" );
1414 }
1415
1416 //=======================================================================
1417 //function : operator
1418 //purpose  : 
1419 //=======================================================================
1420
1421 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1422
1423 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
1424 {
1425   switch ( e ) {
1426   RETCASE( SEW_OK );
1427   RETCASE( SEW_BORDER1_NOT_FOUND );
1428   RETCASE( SEW_BORDER2_NOT_FOUND );
1429   RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
1430   RETCASE( SEW_BAD_SIDE_NODES );
1431   RETCASE( SEW_VOLUMES_TO_SPLIT );
1432   RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
1433   RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
1434   RETCASE( SEW_BAD_SIDE1_NODES );
1435   RETCASE( SEW_BAD_SIDE2_NODES );
1436   }
1437   return SMESH::SMESH_MeshEditor::SEW_OK;
1438 }
1439
1440 //=======================================================================
1441 //function : SewFreeBorders
1442 //purpose  : 
1443 //=======================================================================
1444
1445 SMESH::SMESH_MeshEditor::Sew_Error
1446   SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
1447                                      CORBA::Long SecondNodeID1,
1448                                      CORBA::Long LastNodeID1,
1449                                      CORBA::Long FirstNodeID2,
1450                                      CORBA::Long SecondNodeID2,
1451                                      CORBA::Long LastNodeID2,
1452                                      CORBA::Boolean CreatePolygons,
1453                                      CORBA::Boolean CreatePolyedrs)
1454 {
1455   SMESHDS_Mesh* aMesh = GetMeshDS();
1456
1457   const SMDS_MeshNode* aBorderFirstNode  = aMesh->FindNode( FirstNodeID1  );
1458   const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1459   const SMDS_MeshNode* aBorderLastNode   = aMesh->FindNode( LastNodeID1   );
1460   const SMDS_MeshNode* aSide2FirstNode   = aMesh->FindNode( FirstNodeID2  );
1461   const SMDS_MeshNode* aSide2SecondNode  = aMesh->FindNode( SecondNodeID2 );
1462   const SMDS_MeshNode* aSide2ThirdNode   = aMesh->FindNode( LastNodeID2   );
1463
1464   if (!aBorderFirstNode ||
1465       !aBorderSecondNode||
1466       !aBorderLastNode)
1467     return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1468   if (!aSide2FirstNode  ||
1469       !aSide2SecondNode ||
1470       !aSide2ThirdNode)
1471     return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1472
1473   // Update Python script
1474   TCollection_AsciiString str ("error = mesh_editor.SewFreeBorders( ");
1475   str += TCollection_AsciiString( (int) FirstNodeID1  )  + ", ";
1476   str += TCollection_AsciiString( (int) SecondNodeID1 )  + ", ";
1477   str += TCollection_AsciiString( (int) LastNodeID1   )  + ", ";
1478   str += TCollection_AsciiString( (int) FirstNodeID2  )  + ", ";
1479   str += TCollection_AsciiString( (int) SecondNodeID2 )  + ", ";
1480   str += TCollection_AsciiString( (int) LastNodeID2   )  + ", ";
1481   str += TCollection_AsciiString( CreatePolygons      )  + ", ";
1482   str += TCollection_AsciiString( CreatePolyedrs      )  + ") ";
1483   SMESH_Gen_i::AddToCurrentPyScript( str );
1484
1485   ::SMESH_MeshEditor anEditor( _myMesh );
1486   return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1487                                             aBorderSecondNode,
1488                                             aBorderLastNode,
1489                                             aSide2FirstNode,
1490                                             aSide2SecondNode,
1491                                             aSide2ThirdNode,
1492                                             true,
1493                                             CreatePolygons,
1494                                             CreatePolyedrs) );
1495 }
1496
1497 //=======================================================================
1498 //function : SewConformFreeBorders
1499 //purpose  : 
1500 //=======================================================================
1501
1502 SMESH::SMESH_MeshEditor::Sew_Error
1503   SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
1504                                             CORBA::Long SecondNodeID1,
1505                                             CORBA::Long LastNodeID1,
1506                                             CORBA::Long FirstNodeID2,
1507                                             CORBA::Long SecondNodeID2)
1508 {
1509   SMESHDS_Mesh* aMesh = GetMeshDS();
1510
1511   const SMDS_MeshNode* aBorderFirstNode  = aMesh->FindNode( FirstNodeID1  );
1512   const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
1513   const SMDS_MeshNode* aBorderLastNode   = aMesh->FindNode( LastNodeID1   );
1514   const SMDS_MeshNode* aSide2FirstNode   = aMesh->FindNode( FirstNodeID2  );
1515   const SMDS_MeshNode* aSide2SecondNode  = aMesh->FindNode( SecondNodeID2 );
1516   const SMDS_MeshNode* aSide2ThirdNode   = 0;
1517
1518   if (!aBorderFirstNode ||
1519       !aBorderSecondNode||
1520       !aBorderLastNode )
1521     return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1522   if (!aSide2FirstNode  ||
1523       !aSide2SecondNode)
1524     return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
1525
1526   // Update Python script
1527   TCollection_AsciiString str ("error = mesh_editor.SewConformFreeBorders( ");
1528   str += TCollection_AsciiString( (int) FirstNodeID1  )  + ", ";
1529   str += TCollection_AsciiString( (int) SecondNodeID1 )  + ", ";
1530   str += TCollection_AsciiString( (int) LastNodeID1   )  + ", ";
1531   str += TCollection_AsciiString( (int) FirstNodeID2  )  + ", ";
1532   str += TCollection_AsciiString( (int) SecondNodeID2 )  + ")";
1533   SMESH_Gen_i::AddToCurrentPyScript( str );
1534
1535   ::SMESH_MeshEditor anEditor( _myMesh );
1536   return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1537                                             aBorderSecondNode,
1538                                             aBorderLastNode,
1539                                             aSide2FirstNode,
1540                                             aSide2SecondNode,
1541                                             aSide2ThirdNode,
1542                                             true,
1543                                             false, false) );
1544 }
1545
1546 //=======================================================================
1547 //function : SewBorderToSide
1548 //purpose  : 
1549 //=======================================================================
1550
1551 SMESH::SMESH_MeshEditor::Sew_Error
1552   SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
1553                                       CORBA::Long SecondNodeIDOnFreeBorder,
1554                                       CORBA::Long LastNodeIDOnFreeBorder,
1555                                       CORBA::Long FirstNodeIDOnSide,
1556                                       CORBA::Long LastNodeIDOnSide,
1557                                       CORBA::Boolean CreatePolygons,
1558                                       CORBA::Boolean CreatePolyedrs)
1559 {
1560   SMESHDS_Mesh* aMesh = GetMeshDS();
1561
1562   const SMDS_MeshNode* aBorderFirstNode  = aMesh->FindNode( FirstNodeIDOnFreeBorder  );
1563   const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
1564   const SMDS_MeshNode* aBorderLastNode   = aMesh->FindNode( LastNodeIDOnFreeBorder   );
1565   const SMDS_MeshNode* aSide2FirstNode   = aMesh->FindNode( FirstNodeIDOnSide  );
1566   const SMDS_MeshNode* aSide2SecondNode  = aMesh->FindNode( LastNodeIDOnSide );
1567   const SMDS_MeshNode* aSide2ThirdNode   = 0;
1568
1569   if (!aBorderFirstNode ||
1570       !aBorderSecondNode||
1571       !aBorderLastNode  )
1572     return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
1573   if (!aSide2FirstNode  ||
1574       !aSide2SecondNode)
1575     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
1576
1577   // Update Python script
1578   TCollection_AsciiString str ("error = mesh_editor.SewBorderToSide( ");
1579   str += TCollection_AsciiString( (int) FirstNodeIDOnFreeBorder  ) + ", ";
1580   str += TCollection_AsciiString( (int) SecondNodeIDOnFreeBorder ) + ", ";
1581   str += TCollection_AsciiString( (int) LastNodeIDOnFreeBorder   ) + ", ";
1582   str += TCollection_AsciiString( (int) FirstNodeIDOnSide        ) + ", ";
1583   str += TCollection_AsciiString( (int) LastNodeIDOnSide         ) + ", ";
1584   str += TCollection_AsciiString( CreatePolygons                 ) + ", ";
1585   str += TCollection_AsciiString( CreatePolyedrs                 ) + ") ";
1586   SMESH_Gen_i::AddToCurrentPyScript( str );
1587
1588   ::SMESH_MeshEditor anEditor( _myMesh );
1589   return convError( anEditor.SewFreeBorder (aBorderFirstNode,
1590                                             aBorderSecondNode,
1591                                             aBorderLastNode,
1592                                             aSide2FirstNode,
1593                                             aSide2SecondNode,
1594                                             aSide2ThirdNode,
1595                                             false,
1596                                             CreatePolygons,
1597                                             CreatePolyedrs) );
1598 }
1599
1600 //=======================================================================
1601 //function : SewSideElements
1602 //purpose  : 
1603 //=======================================================================
1604
1605 SMESH::SMESH_MeshEditor::Sew_Error
1606   SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
1607                                       const SMESH::long_array& IDsOfSide2Elements,
1608                                       CORBA::Long NodeID1OfSide1ToMerge,
1609                                       CORBA::Long NodeID1OfSide2ToMerge,
1610                                       CORBA::Long NodeID2OfSide1ToMerge,
1611                                       CORBA::Long NodeID2OfSide2ToMerge)
1612 {
1613   SMESHDS_Mesh* aMesh = GetMeshDS();
1614
1615   const SMDS_MeshNode* aFirstNode1ToMerge  = aMesh->FindNode( NodeID1OfSide1ToMerge );
1616   const SMDS_MeshNode* aFirstNode2ToMerge  = aMesh->FindNode( NodeID1OfSide2ToMerge );
1617   const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
1618   const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
1619
1620   if (!aFirstNode1ToMerge ||
1621       !aFirstNode2ToMerge )
1622     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
1623   if (!aSecondNode1ToMerge||
1624       !aSecondNode2ToMerge)
1625     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
1626
1627   set<const SMDS_MeshElement*> aSide1Elems, aSide2Elems;
1628   for (int i = 0; i < IDsOfSide1Elements.length(); i++)
1629   {
1630     CORBA::Long index = IDsOfSide1Elements[i];
1631     const SMDS_MeshElement * elem = aMesh->FindElement(index);
1632     if ( elem )
1633       aSide1Elems.insert( elem );
1634   }
1635   for (int i = 0; i < IDsOfSide2Elements.length(); i++)
1636   {
1637     CORBA::Long index = IDsOfSide2Elements[i];
1638     const SMDS_MeshElement * elem = aMesh->FindElement(index);
1639     if ( elem )
1640       aSide2Elems.insert( elem );
1641   }
1642   // Update Python script
1643   TCollection_AsciiString str ("error = mesh_editor.SewSideElements( ");
1644   SMESH_Gen_i::AddArray( str, IDsOfSide1Elements ) += ", ";
1645   SMESH_Gen_i::AddArray( str, IDsOfSide2Elements ) += ", ";
1646   str += TCollection_AsciiString( (int) NodeID1OfSide1ToMerge ) + ", ";
1647   str += TCollection_AsciiString( (int) NodeID1OfSide2ToMerge ) + ", ";
1648   str += TCollection_AsciiString( (int) NodeID2OfSide1ToMerge ) + ", ";
1649   str += TCollection_AsciiString( (int) NodeID2OfSide2ToMerge ) + ")";
1650   SMESH_Gen_i::AddToCurrentPyScript( str );
1651
1652   ::SMESH_MeshEditor anEditor( _myMesh );
1653   return convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
1654                                               aFirstNode1ToMerge,
1655                                               aFirstNode2ToMerge,
1656                                               aSecondNode1ToMerge,
1657                                               aSecondNode2ToMerge));
1658 }