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