Salome HOME
Update copyright information
[modules/smesh.git] / src / SMESH_I / SMESH_MeshEditor_i.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
23 //  File   : SMESH_MeshEditor_i.cxx
24 //  Author : Nicolas REJNERI
25 //  Module : SMESH
26 //  $Header$
27 //
28 #include "SMESH_MeshEditor_i.hxx"
29
30 #include "SMDS_MeshEdge.hxx"
31 #include "SMDS_MeshFace.hxx"
32 #include "SMDS_MeshVolume.hxx"
33 #include "SMDS_PolyhedralVolumeOfNodes.hxx"
34 #include "SMESH_MeshEditor.hxx"
35 #include "SMESH_subMeshEventListener.hxx"
36 #include "SMESH_Gen_i.hxx"
37 #include "SMESH_Filter_i.hxx"
38 #include "SMESH_PythonDump.hxx"
39
40 #include "utilities.h"
41 #include "Utils_ExceptHandlers.hxx"
42 #include "Utils_CorbaException.hxx"
43
44 #include <BRepAdaptor_Surface.hxx>
45 #include <BRep_Tool.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include <TopoDS.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <gp_Ax1.hxx>
51 #include <gp_Ax2.hxx>
52 #include <gp_Vec.hxx>
53
54 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
55 #define NO_CAS_CATCH
56 #endif
57
58 #include <Standard_Failure.hxx>
59
60 #ifdef NO_CAS_CATCH
61 #include <Standard_ErrorHandler.hxx>
62 #endif
63
64 #include <sstream>
65
66 #define cast2Node(elem) static_cast<const SMDS_MeshNode*>( elem )
67
68 using namespace std;
69 using SMESH::TPythonDump;
70
71 namespace {
72
73   //=============================================================================
74   /*!
75    * \brief Mesh to apply modifications for preview purposes
76    */
77   //=============================================================================
78
79   struct TPreviewMesh: public SMESH_Mesh
80   {
81     SMDSAbs_ElementType myPreviewType; // type to show
82     //!< Constructor
83     TPreviewMesh(SMDSAbs_ElementType previewElements = SMDSAbs_All) {
84       _isShapeToMesh = _id =_studyId =_idDoc = 0;
85       _myMeshDS  = new SMESHDS_Mesh( _id, true );
86       myPreviewType = previewElements;
87     }
88     //!< Destructor
89     virtual ~TPreviewMesh() { delete _myMeshDS; }
90     //!< Copy a set of elements
91     void Copy(const TIDSortedElemSet & theElements,
92               TIDSortedElemSet&        theCopyElements,
93               SMDSAbs_ElementType      theSelectType = SMDSAbs_All,
94               SMDSAbs_ElementType      theAvoidType = SMDSAbs_All)
95     {
96       // loop on theIDsOfElements
97       TIDSortedElemSet::const_iterator eIt = theElements.begin();
98       for ( ; eIt != theElements.end(); ++eIt )
99       {
100         const SMDS_MeshElement* anElem = *eIt;
101         if ( !anElem ) continue;
102         SMDSAbs_ElementType type = anElem->GetType();
103         if ( type == theAvoidType ||
104              ( theSelectType != SMDSAbs_All && type != theSelectType ))
105           continue;
106
107         if ( const SMDS_MeshElement* anElemCopy = Copy( anElem ))
108           theCopyElements.insert( theCopyElements.end(), anElemCopy );
109       }
110     }
111     //!< Copy an element
112     SMDS_MeshElement* Copy( const SMDS_MeshElement* anElem )
113     {
114       // copy element nodes
115       int anElemNbNodes = anElem->NbNodes();
116       vector< int > anElemNodesID( anElemNbNodes ) ;
117       SMDS_ElemIteratorPtr itElemNodes = anElem->nodesIterator();
118       for ( int i = 0; itElemNodes->more(); i++)
119       {
120         const SMDS_MeshNode* anElemNode = cast2Node( itElemNodes->next() );
121         Copy( anElemNode );
122         anElemNodesID[i] = anElemNode->GetID();
123       }
124
125       // creates a corresponding element on copied nodes
126       SMDS_MeshElement* anElemCopy = 0;
127       if ( anElem->IsPoly() && anElem->GetType() == SMDSAbs_Volume )
128       {
129         const SMDS_PolyhedralVolumeOfNodes* ph =
130           dynamic_cast<const SMDS_PolyhedralVolumeOfNodes*> (anElem);
131         if ( ph )
132           anElemCopy = _myMeshDS->AddPolyhedralVolumeWithID
133             (anElemNodesID, ph->GetQuanities(),anElem->GetID());
134       }
135       else {
136         anElemCopy = ::SMESH_MeshEditor(this).AddElement( anElemNodesID,
137                                                           anElem->GetType(),
138                                                           anElem->IsPoly() );
139       }
140       return anElemCopy;
141     }
142     //!< Copy a node
143     SMDS_MeshNode* Copy( const SMDS_MeshNode* anElemNode )
144     {
145       return _myMeshDS->AddNodeWithID(anElemNode->X(), anElemNode->Y(), anElemNode->Z(), 
146                                       anElemNode->GetID());
147     }
148   };// struct TPreviewMesh
149
150   static SMESH_NodeSearcher * myNodeSearcher = 0;
151
152   //=============================================================================
153   /*!
154    * \brief Deleter of myNodeSearcher at any compute event occured
155    */
156   //=============================================================================
157
158   struct TNodeSearcherDeleter : public SMESH_subMeshEventListener
159   {
160     SMESH_Mesh* myMesh;
161     //!< Constructor
162     TNodeSearcherDeleter(): SMESH_subMeshEventListener( false ), // won't be deleted by submesh
163     myMesh(0) {}
164     //!< Delete myNodeSearcher
165     static void Delete()
166     {
167       if ( myNodeSearcher ) { delete myNodeSearcher; myNodeSearcher = 0; }
168     }
169     typedef map < int, SMESH_subMesh * > TDependsOnMap;
170     //!< The meshod called by submesh: do my main job
171     void ProcessEvent(const int, const int eventType, SMESH_subMesh* sm,
172                       SMESH_subMeshEventListenerData*,const SMESH_Hypothesis*)
173     {
174       if ( eventType == SMESH_subMesh::COMPUTE_EVENT ) {
175         Delete();
176         Unset( sm->GetFather() );
177       }
178     }
179     //!< set self on all submeshes and delete myNodeSearcher if other mesh is set
180     void Set(SMESH_Mesh* mesh)
181     {
182       if ( myMesh && myMesh != mesh ) {
183         Delete();
184         Unset( myMesh );
185       }
186       myMesh = mesh;
187       if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
188         const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
189         TDependsOnMap::const_iterator sm;
190         for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
191           sm->second->SetEventListener( this, 0, sm->second );
192       }
193     }
194     //!<  delete self from all submeshes
195     void Unset(SMESH_Mesh* mesh)
196     {
197       if ( SMESH_subMesh* myMainSubMesh = mesh->GetSubMeshContaining(1) ) {
198         const TDependsOnMap & subMeshes = myMainSubMesh->DependsOn();
199         TDependsOnMap::const_iterator sm;
200         for (sm = subMeshes.begin(); sm != subMeshes.end(); sm++)
201           sm->second->DeleteEventListener( this );
202       }
203     }
204   };
205
206   TCollection_AsciiString mirrorTypeName( SMESH::SMESH_MeshEditor::MirrorType theMirrorType )
207   {
208     TCollection_AsciiString typeStr;
209     switch ( theMirrorType ) {
210     case  SMESH::SMESH_MeshEditor::POINT:
211       typeStr = "SMESH.SMESH_MeshEditor.POINT";
212       break;
213     case  SMESH::SMESH_MeshEditor::AXIS:
214       typeStr = "SMESH.SMESH_MeshEditor.AXIS";
215       break;
216     default:
217       typeStr = "SMESH.SMESH_MeshEditor.PLANE";
218     }
219     return typeStr;
220   }
221 }
222
223 //=============================================================================
224 /*!
225  *
226  */
227 //=============================================================================
228
229 SMESH_MeshEditor_i::SMESH_MeshEditor_i(SMESH_Mesh_i* theMesh, bool isPreview)
230 {
231   myMesh_i = theMesh;
232   myMesh = & theMesh->GetImpl();
233   myPreviewMode = isPreview;
234 }
235
236 //================================================================================
237 /*!
238  * \brief Destructor
239  */
240 //================================================================================
241
242 SMESH_MeshEditor_i::~SMESH_MeshEditor_i()
243 {
244 }
245
246 //================================================================================
247 /*!
248  * \brief Clear members
249  */
250 //================================================================================
251
252 void SMESH_MeshEditor_i::initData()
253 {
254   if ( myPreviewMode ) {
255     myPreviewData = new SMESH::MeshPreviewStruct();
256   }
257   else {
258     myLastCreatedElems = new SMESH::long_array();
259     myLastCreatedNodes = new SMESH::long_array();
260     TNodeSearcherDeleter::Delete();
261   }
262 }
263
264 //=============================================================================
265 /*!
266  *
267  */
268 //=============================================================================
269
270 CORBA::Boolean
271   SMESH_MeshEditor_i::RemoveElements(const SMESH::long_array & IDsOfElements)
272 {
273   initData();
274
275   ::SMESH_MeshEditor anEditor( myMesh );
276   list< int > IdList;
277
278   for (int i = 0; i < IDsOfElements.length(); i++)
279     IdList.push_back( IDsOfElements[i] );
280
281   // Update Python script
282   TPythonDump() << "isDone = " << this << ".RemoveElements( " << IDsOfElements << " )";
283 #ifdef _DEBUG_
284   TPythonDump() << "print 'RemoveElements: ', isDone";
285 #endif
286   // Remove Elements
287   return anEditor.Remove( IdList, false );
288 }
289
290 //=============================================================================
291 /*!
292  *
293  */
294 //=============================================================================
295
296 CORBA::Boolean SMESH_MeshEditor_i::RemoveNodes(const SMESH::long_array & IDsOfNodes)
297 {
298   initData();
299
300   ::SMESH_MeshEditor anEditor( myMesh );
301   list< int > IdList;
302   for (int i = 0; i < IDsOfNodes.length(); i++)
303     IdList.push_back( IDsOfNodes[i] );
304
305   // Update Python script
306   TPythonDump() << "isDone = " << this << ".RemoveNodes( " << IDsOfNodes << " )";
307 #ifdef _DEBUG_
308   TPythonDump() << "print 'RemoveNodes: ', isDone";
309 #endif
310
311   return anEditor.Remove( IdList, true );
312 }
313
314 //=============================================================================
315 /*!
316  *
317  */
318 //=============================================================================
319
320 CORBA::Long SMESH_MeshEditor_i::AddEdge(const SMESH::long_array & IDsOfNodes)
321 {
322   initData();
323
324   int NbNodes = IDsOfNodes.length();
325   SMDS_MeshElement* elem = 0;
326   if (NbNodes == 2)
327   {
328     CORBA::Long index1 = IDsOfNodes[0];
329     CORBA::Long index2 = IDsOfNodes[1];
330     elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(index1), GetMeshDS()->FindNode(index2));
331
332     // Update Python script
333     TPythonDump() << "edge = " << this << ".AddEdge([ "
334                   << index1 << ", " << index2 <<" ])";
335   }
336   if (NbNodes == 3) {
337     CORBA::Long n1 = IDsOfNodes[0];
338     CORBA::Long n2 = IDsOfNodes[1];
339     CORBA::Long n12 = IDsOfNodes[2];
340     elem = GetMeshDS()->AddEdge(GetMeshDS()->FindNode(n1),
341                                 GetMeshDS()->FindNode(n2),
342                                 GetMeshDS()->FindNode(n12));
343     // Update Python script
344     TPythonDump() << "edgeID = " << this << ".AddEdge([ "
345                   <<n1<<", "<<n2<<", "<<n12<<" ])";
346   }
347
348   if(elem)
349     return elem->GetID();
350
351   return 0;
352 }
353
354 //=============================================================================
355 /*!
356  *
357  */
358 //=============================================================================
359
360 CORBA::Long SMESH_MeshEditor_i::AddNode(CORBA::Double x,
361                                         CORBA::Double y, CORBA::Double z)
362 {
363   initData();
364
365   const SMDS_MeshNode* N = GetMeshDS()->AddNode(x, y, z);
366
367   // Update Python script
368   TPythonDump() << "nodeID = " << this << ".AddNode( "
369                 << x << ", " << y << ", " << z << " )";
370
371   return N->GetID();
372 }
373
374 //=============================================================================
375 /*!
376  *  AddFace
377  */
378 //=============================================================================
379
380 CORBA::Long SMESH_MeshEditor_i::AddFace(const SMESH::long_array & IDsOfNodes)
381 {
382   initData();
383
384   int NbNodes = IDsOfNodes.length();
385   if (NbNodes < 3)
386   {
387     return 0;
388   }
389
390   std::vector<const SMDS_MeshNode*> nodes (NbNodes);
391   for (int i = 0; i < NbNodes; i++)
392     nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
393
394   SMDS_MeshElement* elem = 0;
395   if (NbNodes == 3) {
396     elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2]);
397   }
398   else if (NbNodes == 4) {
399     elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3]);
400   }
401   else if (NbNodes == 6) {
402     elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
403                                 nodes[4], nodes[5]);
404   }
405   else if (NbNodes == 8) {
406     elem = GetMeshDS()->AddFace(nodes[0], nodes[1], nodes[2], nodes[3],
407                                 nodes[4], nodes[5], nodes[6], nodes[7]);
408   }
409
410   // Update Python script
411   TPythonDump() << "faceID = " << this << ".AddFace( " << IDsOfNodes << " )";
412
413   if(elem)
414     return elem->GetID();
415
416   return 0;
417 }
418
419 //=============================================================================
420 /*!
421  *  AddPolygonalFace
422  */
423 //=============================================================================
424 CORBA::Long SMESH_MeshEditor_i::AddPolygonalFace
425                                    (const SMESH::long_array & IDsOfNodes)
426 {
427   initData();
428
429   int NbNodes = IDsOfNodes.length();
430   std::vector<const SMDS_MeshNode*> nodes (NbNodes);
431   for (int i = 0; i < NbNodes; i++)
432     nodes[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
433
434   const SMDS_MeshElement* elem = GetMeshDS()->AddPolygonalFace(nodes);
435   
436   // Update Python script
437   TPythonDump() <<"faceID = "<<this<<".AddPolygonalFace( "<<IDsOfNodes<<" )";
438 #ifdef _DEBUG_
439   TPythonDump() << "print 'AddPolygonalFace: ', faceID";
440 #endif
441
442   if(elem)
443     return elem->GetID();
444
445   return 0;
446 }
447
448 //=============================================================================
449 /*!
450  *
451  */
452 //=============================================================================
453
454 CORBA::Long SMESH_MeshEditor_i::AddVolume(const SMESH::long_array & IDsOfNodes)
455 {
456   initData();
457
458   int NbNodes = IDsOfNodes.length();
459   vector< const SMDS_MeshNode*> n(NbNodes);
460   for(int i=0;i<NbNodes;i++)
461     n[i]=GetMeshDS()->FindNode(IDsOfNodes[i]);
462
463   SMDS_MeshElement* elem = 0;
464   switch(NbNodes)
465   {
466   case 4 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3]); break;
467   case 5 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4]); break;
468   case 6 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5]); break;
469   case 8 :elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7]); break;
470   case 10:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],
471                                         n[6],n[7],n[8],n[9]);
472     break;
473   case 13:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],
474                                         n[7],n[8],n[9],n[10],n[11],n[12]);
475     break;
476   case 15:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],n[8],
477                                         n[9],n[10],n[11],n[12],n[13],n[14]);
478     break;
479   case 20:elem = GetMeshDS()->AddVolume(n[0],n[1],n[2],n[3],n[4],n[5],n[6],n[7],
480                                         n[8],n[9],n[10],n[11],n[12],n[13],n[14],
481                                         n[15],n[16],n[17],n[18],n[19]);
482     break;
483   }
484
485   // Update Python script
486   TPythonDump() << "volID = " << this << ".AddVolume( " << IDsOfNodes << " )";
487 #ifdef _DEBUG_
488   TPythonDump() << "print 'AddVolume: ', volID";
489 #endif
490
491   if(elem)
492     return elem->GetID();
493
494   return 0;
495 }
496
497 //=============================================================================
498 /*!
499  *  AddPolyhedralVolume
500  */
501 //=============================================================================
502 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolume
503                                    (const SMESH::long_array & IDsOfNodes,
504                                     const SMESH::long_array & Quantities)
505 {
506   initData();
507
508   int NbNodes = IDsOfNodes.length();
509   std::vector<const SMDS_MeshNode*> n (NbNodes);
510   for (int i = 0; i < NbNodes; i++)
511     n[i] = GetMeshDS()->FindNode(IDsOfNodes[i]);
512
513   int NbFaces = Quantities.length();
514   std::vector<int> q (NbFaces);
515   for (int j = 0; j < NbFaces; j++)
516     q[j] = Quantities[j];
517
518   const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(n, q);
519
520   // Update Python script
521   TPythonDump() << "volID = " << this << ".AddPolyhedralVolume( "
522                 << IDsOfNodes << ", " << Quantities << " )";
523 #ifdef _DEBUG_
524   TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
525 #endif
526
527   if(elem)
528     return elem->GetID();
529
530   return 0;
531 }
532
533 //=============================================================================
534 /*!
535  *  AddPolyhedralVolumeByFaces
536  */
537 //=============================================================================
538 CORBA::Long SMESH_MeshEditor_i::AddPolyhedralVolumeByFaces
539                                    (const SMESH::long_array & IdsOfFaces)
540 {
541   initData();
542
543   int NbFaces = IdsOfFaces.length();
544   std::vector<const SMDS_MeshNode*> poly_nodes;
545   std::vector<int> quantities (NbFaces);
546
547   for (int i = 0; i < NbFaces; i++) {
548     const SMDS_MeshElement* aFace = GetMeshDS()->FindElement(IdsOfFaces[i]);
549     quantities[i] = aFace->NbNodes();
550
551     SMDS_ElemIteratorPtr It = aFace->nodesIterator();
552     while (It->more()) {
553       poly_nodes.push_back(static_cast<const SMDS_MeshNode *>(It->next()));
554     }
555   }
556
557   const SMDS_MeshElement* elem = GetMeshDS()->AddPolyhedralVolume(poly_nodes, quantities);
558
559   // Update Python script
560   TPythonDump() << "volID = " << this << ".AddPolyhedralVolumeByFaces( "
561                 << IdsOfFaces << " )";
562 #ifdef _DEBUG_
563   TPythonDump() << "print 'AddPolyhedralVolume: ', volID";
564 #endif
565
566   if(elem)
567     return elem->GetID();
568
569   return 0;
570 }
571
572 //=============================================================================
573 /*!
574  * \brief Bind a node to a vertex
575  * \param NodeID - node ID
576  * \param VertexID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
577  * \retval boolean - false if NodeID or VertexID is invalid
578  */
579 //=============================================================================
580
581 void SMESH_MeshEditor_i::SetNodeOnVertex(CORBA::Long NodeID, CORBA::Long VertexID)
582   throw (SALOME::SALOME_Exception)
583 {
584   Unexpect aCatch(SALOME_SalomeException);
585
586   SMESHDS_Mesh * mesh = GetMeshDS();
587   SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
588   if ( !node )
589     THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
590
591   if ( mesh->MaxShapeIndex() < VertexID )
592     THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
593
594   TopoDS_Shape shape = mesh->IndexToShape( VertexID );
595   if ( shape.ShapeType() != TopAbs_VERTEX )
596     THROW_SALOME_CORBA_EXCEPTION("Invalid VertexID", SALOME::BAD_PARAM);
597
598   mesh->SetNodeOnVertex( node, VertexID );
599 }
600
601 //=============================================================================
602 /*!
603  * \brief Store node position on an edge
604  * \param NodeID - node ID
605  * \param EdgeID - edge ID available through GEOM_Object.GetSubShapeIndices()[0]
606  * \param paramOnEdge - parameter on edge where the node is located
607  * \retval boolean - false if any parameter is invalid
608  */
609 //=============================================================================
610
611 void SMESH_MeshEditor_i::SetNodeOnEdge(CORBA::Long NodeID, CORBA::Long EdgeID,
612                                        CORBA::Double paramOnEdge)
613   throw (SALOME::SALOME_Exception)
614 {
615   Unexpect aCatch(SALOME_SalomeException);
616
617   SMESHDS_Mesh * mesh = GetMeshDS();
618   SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
619   if ( !node )
620     THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
621
622   if ( mesh->MaxShapeIndex() < EdgeID )
623     THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
624
625   TopoDS_Shape shape = mesh->IndexToShape( EdgeID );
626   if ( shape.ShapeType() != TopAbs_EDGE )
627     THROW_SALOME_CORBA_EXCEPTION("Invalid EdgeID", SALOME::BAD_PARAM);
628
629   Standard_Real f,l;
630   BRep_Tool::Range( TopoDS::Edge( shape ), f,l);
631   if ( paramOnEdge < f || paramOnEdge > l )
632     THROW_SALOME_CORBA_EXCEPTION("Invalid paramOnEdge", SALOME::BAD_PARAM);
633
634   mesh->SetNodeOnEdge( node, EdgeID, paramOnEdge );
635 }
636
637 //=============================================================================
638 /*!
639  * \brief Store node position on a face
640  * \param NodeID - node ID
641  * \param FaceID - face ID available through GEOM_Object.GetSubShapeIndices()[0]
642  * \param u - U parameter on face where the node is located
643  * \param v - V parameter on face where the node is located
644  * \retval boolean - false if any parameter is invalid
645  */
646 //=============================================================================
647
648 void SMESH_MeshEditor_i::SetNodeOnFace(CORBA::Long NodeID, CORBA::Long FaceID,
649                                        CORBA::Double u, CORBA::Double v)
650   throw (SALOME::SALOME_Exception)
651 {
652   Unexpect aCatch(SALOME_SalomeException);
653
654   SMESHDS_Mesh * mesh = GetMeshDS();
655   SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
656   if ( !node )
657     THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
658
659   if ( mesh->MaxShapeIndex() < FaceID )
660     THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
661
662   TopoDS_Shape shape = mesh->IndexToShape( FaceID );
663   if ( shape.ShapeType() != TopAbs_FACE )
664     THROW_SALOME_CORBA_EXCEPTION("Invalid FaceID", SALOME::BAD_PARAM);
665
666   BRepAdaptor_Surface surf( TopoDS::Face( shape ));
667   bool isOut = ( u < surf.FirstUParameter() ||
668                  u > surf.LastUParameter()  ||
669                  v < surf.FirstVParameter() ||
670                  v > surf.LastVParameter() );
671
672   if ( isOut ) {
673 #ifdef _DEBUG_
674     MESSAGE ( "FACE " << FaceID << " (" << u << "," << v << ") out of "
675            << " u( " <<  surf.FirstUParameter() 
676            << "," <<  surf.LastUParameter()  
677            << ") v( " <<  surf.FirstVParameter() 
678            << "," <<  surf.LastVParameter() << ")" );
679 #endif    
680     THROW_SALOME_CORBA_EXCEPTION("Invalid UV", SALOME::BAD_PARAM);
681   }
682
683   mesh->SetNodeOnFace( node, FaceID, u, v );
684 }
685
686 //=============================================================================
687 /*!
688  * \brief Bind a node to a solid
689  * \param NodeID - node ID
690  * \param SolidID - vertex ID available through GEOM_Object.GetSubShapeIndices()[0]
691  * \retval boolean - false if NodeID or SolidID is invalid
692  */
693 //=============================================================================
694
695 void SMESH_MeshEditor_i::SetNodeInVolume(CORBA::Long NodeID, CORBA::Long SolidID)
696   throw (SALOME::SALOME_Exception)
697 {
698   Unexpect aCatch(SALOME_SalomeException);
699
700   SMESHDS_Mesh * mesh = GetMeshDS();
701   SMDS_MeshNode* node = const_cast<SMDS_MeshNode*>( mesh->FindNode(NodeID) );
702   if ( !node )
703     THROW_SALOME_CORBA_EXCEPTION("Invalid NodeID", SALOME::BAD_PARAM);
704
705   if ( mesh->MaxShapeIndex() < SolidID )
706     THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
707
708   TopoDS_Shape shape = mesh->IndexToShape( SolidID );
709   if ( shape.ShapeType() != TopAbs_SOLID &&
710        shape.ShapeType() != TopAbs_SHELL)
711     THROW_SALOME_CORBA_EXCEPTION("Invalid SolidID", SALOME::BAD_PARAM);
712
713   mesh->SetNodeInVolume( node, SolidID );
714 }
715
716 //=============================================================================
717 /*!
718  * \brief Bind an element to a shape
719  * \param ElementID - element ID
720  * \param ShapeID - shape ID available through GEOM_Object.GetSubShapeIndices()[0]
721  * \retval boolean - false if ElementID or ShapeID is invalid
722  */
723 //=============================================================================
724
725 void SMESH_MeshEditor_i::SetMeshElementOnShape(CORBA::Long ElementID,
726                                                CORBA::Long ShapeID)
727   throw (SALOME::SALOME_Exception)
728 {
729   Unexpect aCatch(SALOME_SalomeException);
730
731   SMESHDS_Mesh * mesh = GetMeshDS();
732   SMDS_MeshElement* elem = const_cast<SMDS_MeshElement*>(mesh->FindElement(ElementID));
733   if ( !elem )
734     THROW_SALOME_CORBA_EXCEPTION("Invalid ElementID", SALOME::BAD_PARAM);
735
736   if ( mesh->MaxShapeIndex() < ShapeID )
737     THROW_SALOME_CORBA_EXCEPTION("Invalid ShapeID", SALOME::BAD_PARAM);
738
739   TopoDS_Shape shape = mesh->IndexToShape( ShapeID );
740   if ( shape.ShapeType() != TopAbs_EDGE &&
741        shape.ShapeType() != TopAbs_FACE &&
742        shape.ShapeType() != TopAbs_SOLID &&
743        shape.ShapeType() != TopAbs_SHELL )
744     THROW_SALOME_CORBA_EXCEPTION("Invalid shape type", SALOME::BAD_PARAM);
745
746   mesh->SetMeshElementOnShape( elem, ShapeID );
747 }
748
749
750 //=============================================================================
751 /*!
752  *
753  */
754 //=============================================================================
755
756 CORBA::Boolean SMESH_MeshEditor_i::MoveNode(CORBA::Long   NodeID,
757                                             CORBA::Double x,
758                                             CORBA::Double y,
759                                             CORBA::Double z)
760 {
761   initData();
762
763   const SMDS_MeshNode * node = GetMeshDS()->FindNode( NodeID );
764   if ( !node )
765     return false;
766
767   GetMeshDS()->MoveNode(node, x, y, z);
768
769   // Update Python script
770   TPythonDump() << "isDone = " << this << ".MoveNode( "
771                 << NodeID << ", " << x << ", " << y << ", " << z << " )";
772
773   return true;
774 }
775
776 //=============================================================================
777 /*!
778  *
779  */
780 //=============================================================================
781
782 CORBA::Boolean SMESH_MeshEditor_i::InverseDiag(CORBA::Long NodeID1,
783                                                CORBA::Long NodeID2)
784 {
785   initData();
786
787   const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
788   const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
789   if ( !n1 || !n2 )
790     return false;
791
792   // Update Python script
793   TPythonDump() << "isDone = " << this << ".InverseDiag( "
794                 << NodeID1 << ", " << NodeID2 << " )";
795
796   ::SMESH_MeshEditor aMeshEditor( myMesh );
797   return aMeshEditor.InverseDiag ( n1, n2 );
798 }
799
800 //=============================================================================
801 /*!
802  *
803  */
804 //=============================================================================
805
806 CORBA::Boolean SMESH_MeshEditor_i::DeleteDiag(CORBA::Long NodeID1,
807                                               CORBA::Long NodeID2)
808 {
809   initData();
810
811   const SMDS_MeshNode * n1 = GetMeshDS()->FindNode( NodeID1 );
812   const SMDS_MeshNode * n2 = GetMeshDS()->FindNode( NodeID2 );
813   if ( !n1 || !n2 )
814     return false;
815
816   // Update Python script
817   TPythonDump() << "isDone = " << this << ".DeleteDiag( "
818                 << NodeID1 << ", " << NodeID2 <<  " )";
819
820   ::SMESH_MeshEditor aMeshEditor( myMesh );
821
822   bool stat = aMeshEditor.DeleteDiag ( n1, n2 );
823
824   storeResult(aMeshEditor);
825
826   return stat;
827 }
828
829 //=============================================================================
830 /*!
831  *
832  */
833 //=============================================================================
834
835 CORBA::Boolean SMESH_MeshEditor_i::Reorient(const SMESH::long_array & IDsOfElements)
836 {
837   initData();
838
839   ::SMESH_MeshEditor anEditor( myMesh );
840   for (int i = 0; i < IDsOfElements.length(); i++)
841   {
842     CORBA::Long index = IDsOfElements[i];
843     const SMDS_MeshElement * elem = GetMeshDS()->FindElement(index);
844     if ( elem )
845       anEditor.Reorient( elem );
846   }
847   // Update Python script
848   TPythonDump() << "isDone = " << this << ".Reorient( " << IDsOfElements << " )";
849
850   return true;
851 }
852
853
854 //=============================================================================
855 /*!
856  *
857  */
858 //=============================================================================
859
860 CORBA::Boolean SMESH_MeshEditor_i::ReorientObject(SMESH::SMESH_IDSource_ptr theObject)
861 {
862   initData();
863
864   SMESH::long_array_var anElementsId = theObject->GetIDs();
865   CORBA::Boolean isDone = Reorient(anElementsId);
866
867   // Clear python line, created by Reorient()
868   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
869   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
870
871   // Update Python script
872   TPythonDump() << "isDone = " << this << ".ReorientObject( " << theObject << " )";
873
874   return isDone;
875 }
876
877 namespace
878 {
879   //================================================================================
880   /*!
881    * \brief function for conversion long_array to TIDSortedElemSet
882     * \param IDs - array of IDs
883     * \param aMesh - mesh
884     * \param aMap - collection to fill
885     * \param aType - element type
886    */
887   //================================================================================
888
889   void arrayToSet(const SMESH::long_array & IDs,
890                   const SMESHDS_Mesh*       aMesh,
891                   TIDSortedElemSet&         aMap,
892                   const SMDSAbs_ElementType aType = SMDSAbs_All )
893   { 
894     for (int i=0; i<IDs.length(); i++) {
895       CORBA::Long ind = IDs[i];
896       const SMDS_MeshElement * elem = aMesh->FindElement(ind);
897       if ( elem && ( aType == SMDSAbs_All || elem->GetType() == aType ))
898         aMap.insert( elem );
899     }
900   }
901 }
902
903 //=============================================================================
904 /*!
905  *
906  */
907 //=============================================================================
908 CORBA::Boolean SMESH_MeshEditor_i::TriToQuad (const SMESH::long_array &   IDsOfElements,
909                                               SMESH::NumericalFunctor_ptr Criterion,
910                                               CORBA::Double               MaxAngle)
911 {
912   initData();
913
914   SMESHDS_Mesh* aMesh = GetMeshDS();
915   TIDSortedElemSet faces;
916   arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
917
918   SMESH::NumericalFunctor_i* aNumericalFunctor =
919     dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
920   SMESH::Controls::NumericalFunctorPtr aCrit;
921   if ( !aNumericalFunctor )
922     aCrit.reset( new SMESH::Controls::AspectRatio() );
923   else
924     aCrit = aNumericalFunctor->GetNumericalFunctor();
925
926   // Update Python script
927   TPythonDump() << "isDone = " << this << ".TriToQuad( "
928                 << IDsOfElements << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
929 #ifdef _DEBUG_
930   TPythonDump() << "print 'TriToQuad: ', isDone";
931 #endif
932
933   ::SMESH_MeshEditor anEditor( myMesh );
934
935   bool stat = anEditor.TriToQuad( faces, aCrit, MaxAngle );
936
937   storeResult(anEditor);
938
939   return stat;
940 }
941
942
943 //=============================================================================
944 /*!
945  *
946  */
947 //=============================================================================
948 CORBA::Boolean SMESH_MeshEditor_i::TriToQuadObject (SMESH::SMESH_IDSource_ptr   theObject,
949                                                     SMESH::NumericalFunctor_ptr Criterion,
950                                                     CORBA::Double               MaxAngle)
951 {
952   initData();
953
954   SMESH::long_array_var anElementsId = theObject->GetIDs();
955   CORBA::Boolean isDone = TriToQuad(anElementsId, Criterion, MaxAngle);
956
957   // Clear python line(s), created by TriToQuad()
958   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
959   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
960 #ifdef _DEBUG_
961   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
962 #endif
963
964   SMESH::NumericalFunctor_i* aNumericalFunctor =
965     SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
966
967   // Update Python script
968   TPythonDump() << "isDone = " << this << ".TriToQuadObject("
969                 << theObject << ", " << aNumericalFunctor << ", " << MaxAngle << " )";
970 #ifdef _DEBUG_
971   TPythonDump() << "print 'TriToQuadObject: ', isDone";
972 #endif
973
974   return isDone;
975 }
976
977
978 //=============================================================================
979 /*!
980  *
981  */
982 //=============================================================================
983 CORBA::Boolean SMESH_MeshEditor_i::QuadToTri (const SMESH::long_array &   IDsOfElements,
984                                               SMESH::NumericalFunctor_ptr Criterion)
985 {
986   initData();
987
988   SMESHDS_Mesh* aMesh = GetMeshDS();
989   TIDSortedElemSet faces;
990   arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
991
992   SMESH::NumericalFunctor_i* aNumericalFunctor =
993     dynamic_cast<SMESH::NumericalFunctor_i*>( SMESH_Gen_i::GetServant( Criterion ).in() );
994   SMESH::Controls::NumericalFunctorPtr aCrit;
995   if ( !aNumericalFunctor )
996     aCrit.reset( new SMESH::Controls::AspectRatio() );
997   else
998     aCrit = aNumericalFunctor->GetNumericalFunctor();
999
1000
1001   // Update Python script
1002   TPythonDump() << "isDone = " << this << ".QuadToTri( " << IDsOfElements << ", " << aNumericalFunctor << " )";
1003 #ifdef _DEBUG_
1004   TPythonDump() << "print 'QuadToTri: ', isDone";
1005 #endif
1006
1007   ::SMESH_MeshEditor anEditor( myMesh );
1008   CORBA::Boolean stat = anEditor.QuadToTri( faces, aCrit );
1009
1010   storeResult(anEditor);
1011
1012   return stat;
1013 }
1014
1015
1016 //=============================================================================
1017 /*!
1018  *
1019  */
1020 //=============================================================================
1021 CORBA::Boolean SMESH_MeshEditor_i::QuadToTriObject (SMESH::SMESH_IDSource_ptr   theObject,
1022                                                     SMESH::NumericalFunctor_ptr Criterion)
1023 {
1024   initData();
1025
1026   SMESH::long_array_var anElementsId = theObject->GetIDs();
1027   CORBA::Boolean isDone = QuadToTri(anElementsId, Criterion);
1028
1029   // Clear python line(s), created by QuadToTri()
1030   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1031   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1032 #ifdef _DEBUG_
1033   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1034 #endif
1035
1036   SMESH::NumericalFunctor_i* aNumericalFunctor =
1037     SMESH::DownCast<SMESH::NumericalFunctor_i*>( Criterion );
1038
1039   // Update Python script
1040   TPythonDump() << "isDone = " << this << ".QuadToTriObject( " << theObject << ", " << aNumericalFunctor << " )";
1041 #ifdef _DEBUG_
1042   TPythonDump() << "print 'QuadToTriObject: ', isDone";
1043 #endif
1044
1045   return isDone;
1046 }
1047
1048
1049 //=============================================================================
1050 /*!
1051  *
1052  */
1053 //=============================================================================
1054 CORBA::Boolean SMESH_MeshEditor_i::SplitQuad (const SMESH::long_array & IDsOfElements,
1055                                               CORBA::Boolean            Diag13)
1056 {
1057   initData();
1058
1059   SMESHDS_Mesh* aMesh = GetMeshDS();
1060   TIDSortedElemSet faces;
1061   arrayToSet(IDsOfElements, aMesh, faces, SMDSAbs_Face);
1062
1063   // Update Python script
1064   TPythonDump() << "isDone = " << this << ".SplitQuad( "
1065                 << IDsOfElements << ", " << Diag13 << " )";
1066 #ifdef _DEBUG_
1067   TPythonDump() << "print 'SplitQuad: ', isDone";
1068 #endif
1069
1070   ::SMESH_MeshEditor anEditor( myMesh );
1071   CORBA::Boolean stat = anEditor.QuadToTri( faces, Diag13 );
1072
1073   storeResult(anEditor);
1074
1075   return stat;
1076 }
1077
1078
1079 //=============================================================================
1080 /*!
1081  *
1082  */
1083 //=============================================================================
1084 CORBA::Boolean SMESH_MeshEditor_i::SplitQuadObject (SMESH::SMESH_IDSource_ptr theObject,
1085                                                     CORBA::Boolean            Diag13)
1086 {
1087   initData();
1088
1089   SMESH::long_array_var anElementsId = theObject->GetIDs();
1090   CORBA::Boolean isDone = SplitQuad(anElementsId, Diag13);
1091
1092   // Clear python line(s), created by SplitQuad()
1093   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1094   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1095 #ifdef _DEBUG_
1096   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1097 #endif
1098
1099   // Update Python script
1100   TPythonDump() << "isDone = " << this << ".SplitQuadObject( "
1101                 << theObject << ", " << Diag13 << " )";
1102 #ifdef _DEBUG_
1103   TPythonDump() << "print 'SplitQuadObject: ', isDone";
1104 #endif
1105
1106   return isDone;
1107 }
1108
1109
1110 //=============================================================================
1111 /*!
1112  *  BestSplit
1113  */
1114 //=============================================================================
1115 CORBA::Long SMESH_MeshEditor_i::BestSplit (CORBA::Long                 IDOfQuad,
1116                                            SMESH::NumericalFunctor_ptr Criterion)
1117 {
1118   const SMDS_MeshElement* quad = GetMeshDS()->FindElement(IDOfQuad);
1119   if (quad && quad->GetType() == SMDSAbs_Face && quad->NbNodes() == 4)
1120   {
1121     SMESH::NumericalFunctor_i* aNumericalFunctor =
1122       dynamic_cast<SMESH::NumericalFunctor_i*>(SMESH_Gen_i::GetServant(Criterion).in());
1123     SMESH::Controls::NumericalFunctorPtr aCrit;
1124     if (aNumericalFunctor)
1125       aCrit = aNumericalFunctor->GetNumericalFunctor();
1126     else
1127       aCrit.reset(new SMESH::Controls::AspectRatio());
1128
1129     ::SMESH_MeshEditor anEditor (myMesh);
1130     return anEditor.BestSplit(quad, aCrit);
1131   }
1132   return -1;
1133 }
1134
1135
1136 //=======================================================================
1137 //function : Smooth
1138 //purpose  :
1139 //=======================================================================
1140
1141 CORBA::Boolean
1142   SMESH_MeshEditor_i::Smooth(const SMESH::long_array &              IDsOfElements,
1143                              const SMESH::long_array &              IDsOfFixedNodes,
1144                              CORBA::Long                            MaxNbOfIterations,
1145                              CORBA::Double                          MaxAspectRatio,
1146                              SMESH::SMESH_MeshEditor::Smooth_Method Method)
1147 {
1148   return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1149                 MaxAspectRatio, Method, false );
1150 }
1151
1152
1153 //=======================================================================
1154 //function : SmoothParametric
1155 //purpose  :
1156 //=======================================================================
1157
1158 CORBA::Boolean
1159   SMESH_MeshEditor_i::SmoothParametric(const SMESH::long_array &              IDsOfElements,
1160                                        const SMESH::long_array &              IDsOfFixedNodes,
1161                                        CORBA::Long                            MaxNbOfIterations,
1162                                        CORBA::Double                          MaxAspectRatio,
1163                                        SMESH::SMESH_MeshEditor::Smooth_Method Method)
1164 {
1165   return smooth( IDsOfElements, IDsOfFixedNodes, MaxNbOfIterations,
1166                 MaxAspectRatio, Method, true );
1167 }
1168
1169
1170 //=======================================================================
1171 //function : SmoothObject
1172 //purpose  :
1173 //=======================================================================
1174
1175 CORBA::Boolean
1176   SMESH_MeshEditor_i::SmoothObject(SMESH::SMESH_IDSource_ptr              theObject,
1177                                    const SMESH::long_array &              IDsOfFixedNodes,
1178                                    CORBA::Long                            MaxNbOfIterations,
1179                                    CORBA::Double                          MaxAspectRatio,
1180                                    SMESH::SMESH_MeshEditor::Smooth_Method Method)
1181 {
1182   return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1183                        MaxAspectRatio, Method, false);
1184 }
1185
1186
1187 //=======================================================================
1188 //function : SmoothParametricObject
1189 //purpose  :
1190 //=======================================================================
1191
1192 CORBA::Boolean
1193   SMESH_MeshEditor_i::SmoothParametricObject(SMESH::SMESH_IDSource_ptr              theObject,
1194                                    const SMESH::long_array &              IDsOfFixedNodes,
1195                                    CORBA::Long                            MaxNbOfIterations,
1196                                    CORBA::Double                          MaxAspectRatio,
1197                                    SMESH::SMESH_MeshEditor::Smooth_Method Method)
1198 {
1199   return smoothObject (theObject, IDsOfFixedNodes, MaxNbOfIterations,
1200                        MaxAspectRatio, Method, true);
1201 }
1202
1203
1204 //=============================================================================
1205 /*!
1206  *
1207  */
1208 //=============================================================================
1209
1210 CORBA::Boolean
1211   SMESH_MeshEditor_i::smooth(const SMESH::long_array &              IDsOfElements,
1212                              const SMESH::long_array &              IDsOfFixedNodes,
1213                              CORBA::Long                            MaxNbOfIterations,
1214                              CORBA::Double                          MaxAspectRatio,
1215                              SMESH::SMESH_MeshEditor::Smooth_Method Method,
1216                              bool                                   IsParametric)
1217 {
1218   initData();
1219
1220   SMESHDS_Mesh* aMesh = GetMeshDS();
1221
1222   TIDSortedElemSet elements;
1223   arrayToSet(IDsOfElements, aMesh, elements, SMDSAbs_Face);
1224
1225   set<const SMDS_MeshNode*> fixedNodes;
1226   for (int i = 0; i < IDsOfFixedNodes.length(); i++) {
1227     CORBA::Long index = IDsOfFixedNodes[i];
1228     const SMDS_MeshNode * node = aMesh->FindNode(index);
1229     if ( node )
1230       fixedNodes.insert( node );
1231   }
1232   ::SMESH_MeshEditor::SmoothMethod method = ::SMESH_MeshEditor::LAPLACIAN;
1233   if ( Method != SMESH::SMESH_MeshEditor::LAPLACIAN_SMOOTH )
1234     method = ::SMESH_MeshEditor::CENTROIDAL;
1235
1236   ::SMESH_MeshEditor anEditor( myMesh );
1237   anEditor.Smooth(elements, fixedNodes, method,
1238                   MaxNbOfIterations, MaxAspectRatio, IsParametric );
1239
1240   storeResult(anEditor);
1241
1242   // Update Python script
1243   TPythonDump() << "isDone = " << this << "."
1244                 << (IsParametric ? "SmoothParametric( " : "Smooth( ")
1245                 << IDsOfElements << ", "     << IDsOfFixedNodes << ", "
1246                 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1247                 << "SMESH.SMESH_MeshEditor."
1248                 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1249                      "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1250 #ifdef _DEBUG_
1251   TPythonDump() << "print 'Smooth: ', isDone";
1252 #endif
1253
1254   return true;
1255 }
1256
1257
1258 //=============================================================================
1259 /*!
1260  *
1261  */
1262 //=============================================================================
1263
1264 CORBA::Boolean
1265 SMESH_MeshEditor_i::smoothObject(SMESH::SMESH_IDSource_ptr              theObject,
1266                                  const SMESH::long_array &              IDsOfFixedNodes,
1267                                  CORBA::Long                            MaxNbOfIterations,
1268                                  CORBA::Double                          MaxAspectRatio,
1269                                  SMESH::SMESH_MeshEditor::Smooth_Method Method,
1270                                  bool                                   IsParametric)
1271 {
1272   initData();
1273
1274   SMESH::long_array_var anElementsId = theObject->GetIDs();
1275   CORBA::Boolean isDone = smooth (anElementsId, IDsOfFixedNodes, MaxNbOfIterations,
1276                                   MaxAspectRatio, Method, IsParametric);
1277
1278   // Clear python line(s), created by Smooth()
1279   SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
1280   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1281 #ifdef _DEBUG_
1282   aSMESHGen->RemoveLastFromPythonScript(aSMESHGen->GetCurrentStudyID());
1283 #endif
1284
1285   // Update Python script
1286   TPythonDump() << "isDone = " << this << "."
1287                 << (IsParametric ? "SmoothParametricObject( " : "SmoothObject( ")
1288                 << theObject << ", " << IDsOfFixedNodes << ", "
1289                 << MaxNbOfIterations << ", " << MaxAspectRatio << ", "
1290                 << "SMESH.SMESH_MeshEditor."
1291                 << ( Method == SMESH::SMESH_MeshEditor::CENTROIDAL_SMOOTH ?
1292                      "CENTROIDAL_SMOOTH )" : "LAPLACIAN_SMOOTH )");
1293 #ifdef _DEBUG_
1294   TPythonDump() << "print 'SmoothObject: ', isDone";
1295 #endif
1296
1297   return isDone;
1298 }
1299
1300
1301 //=============================================================================
1302 /*!
1303  *
1304  */
1305 //=============================================================================
1306
1307 void SMESH_MeshEditor_i::RenumberNodes()
1308 {
1309   // Update Python script
1310   TPythonDump() << this << ".RenumberNodes()";
1311
1312   GetMeshDS()->Renumber( true );
1313 }
1314
1315
1316 //=============================================================================
1317 /*!
1318  *
1319  */
1320 //=============================================================================
1321
1322 void SMESH_MeshEditor_i::RenumberElements()
1323 {
1324   // Update Python script
1325   TPythonDump() << this << ".RenumberElements()";
1326
1327   GetMeshDS()->Renumber( false );
1328 }
1329
1330 //=======================================================================
1331   /*!
1332    * \brief Return groups by their IDs
1333    */
1334 //=======================================================================
1335
1336 SMESH::ListOfGroups* SMESH_MeshEditor_i::getGroups(const std::list<int>* groupIDs)
1337 {
1338   if ( !groupIDs )
1339     return 0;
1340   myMesh_i->CreateGroupServants();
1341   return myMesh_i->GetGroups( *groupIDs );
1342 }
1343
1344 //=======================================================================
1345 //function : rotationSweep
1346 //purpose  : 
1347 //=======================================================================
1348
1349 SMESH::ListOfGroups*
1350 SMESH_MeshEditor_i::rotationSweep(const SMESH::long_array & theIDsOfElements,
1351                                   const SMESH::AxisStruct & theAxis,
1352                                   CORBA::Double             theAngleInRadians,
1353                                   CORBA::Long               theNbOfSteps,
1354                                   CORBA::Double             theTolerance,
1355                                   const bool                theMakeGroups)
1356 {
1357   initData();
1358
1359   TIDSortedElemSet inElements, copyElements;
1360   arrayToSet(theIDsOfElements, GetMeshDS(), inElements);
1361
1362   TIDSortedElemSet* workElements = & inElements;
1363   TPreviewMesh      tmpMesh( SMDSAbs_Face );
1364   SMESH_Mesh*       mesh = 0;
1365   bool              makeWalls=true;
1366   if ( myPreviewMode )
1367   {
1368     SMDSAbs_ElementType select = SMDSAbs_All, avoid = SMDSAbs_Volume;
1369     tmpMesh.Copy( inElements, copyElements, select, avoid );
1370     mesh = &tmpMesh;
1371     workElements = & copyElements;
1372     //makeWalls = false;
1373   }
1374   else
1375   {
1376     mesh = myMesh;
1377   }
1378
1379   gp_Ax1 Ax1 (gp_Pnt( theAxis.x,  theAxis.y,  theAxis.z ),
1380               gp_Vec( theAxis.vx, theAxis.vy, theAxis.vz ));
1381
1382   ::SMESH_MeshEditor anEditor( mesh );
1383   ::SMESH_MeshEditor::PGroupIDs groupIds =
1384     anEditor.RotationSweep (*workElements, Ax1, theAngleInRadians,
1385                             theNbOfSteps, theTolerance, theMakeGroups, makeWalls);
1386   storeResult(anEditor);
1387
1388   return theMakeGroups ? getGroups(groupIds.get()) : 0;
1389 }
1390
1391 //=======================================================================
1392 //function : RotationSweep
1393 //purpose  :
1394 //=======================================================================
1395
1396 void SMESH_MeshEditor_i::RotationSweep(const SMESH::long_array & theIDsOfElements,
1397                                        const SMESH::AxisStruct & theAxis,
1398                                        CORBA::Double             theAngleInRadians,
1399                                        CORBA::Long               theNbOfSteps,
1400                                        CORBA::Double             theTolerance)
1401 {
1402   if ( !myPreviewMode ) {
1403     TPythonDump() << "axis = " << theAxis;
1404     TPythonDump() << this << ".RotationSweep( "
1405                   << theIDsOfElements
1406                   << ", axis, "
1407                   << theAngleInRadians << ", "
1408                   << theNbOfSteps << ", "
1409                   << theTolerance << " )";
1410   }
1411   rotationSweep(theIDsOfElements,
1412                 theAxis,
1413                 theAngleInRadians,
1414                 theNbOfSteps,
1415                 theTolerance,
1416                 false);
1417 }
1418
1419 //=======================================================================
1420 //function : RotationSweepMakeGroups
1421 //purpose  : 
1422 //=======================================================================
1423
1424 SMESH::ListOfGroups*
1425 SMESH_MeshEditor_i::RotationSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1426                                             const SMESH::AxisStruct& theAxis,
1427                                             CORBA::Double            theAngleInRadians,
1428                                             CORBA::Long              theNbOfSteps,
1429                                             CORBA::Double            theTolerance)
1430 {
1431   SMESH::ListOfGroups *aGroups = rotationSweep(theIDsOfElements,
1432                                                theAxis,
1433                                                theAngleInRadians,
1434                                                theNbOfSteps,
1435                                                theTolerance,
1436                                                true);
1437   if ( !myPreviewMode ) {
1438     TPythonDump()<< "axis = " << theAxis;
1439     TPythonDump aPythonDump;
1440     DumpGroupsList(aPythonDump,aGroups);
1441     aPythonDump<< this << ".RotationSweepMakeGroups( "
1442                << theIDsOfElements
1443                << ", axis, "
1444                << theAngleInRadians << ", "
1445                << theNbOfSteps << ", "
1446                << theTolerance << " )";
1447   }
1448   return aGroups;
1449 }
1450
1451 //=======================================================================
1452 //function : RotationSweepObject
1453 //purpose  :
1454 //=======================================================================
1455
1456 void SMESH_MeshEditor_i::RotationSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1457                                              const SMESH::AxisStruct & theAxis,
1458                                              CORBA::Double             theAngleInRadians,
1459                                              CORBA::Long               theNbOfSteps,
1460                                              CORBA::Double             theTolerance)
1461 {
1462   if ( !myPreviewMode ) {
1463     TPythonDump() << "axis = " << theAxis;
1464     TPythonDump() << this << ".RotationSweepObject( "
1465                   << theObject
1466                   << ", axis, "
1467                   << theAngleInRadians << ", "
1468                   << theNbOfSteps << ", "
1469                   << theTolerance << " )";
1470   }
1471   SMESH::long_array_var anElementsId = theObject->GetIDs();
1472   rotationSweep(anElementsId,
1473                 theAxis,
1474                 theAngleInRadians,
1475                 theNbOfSteps,
1476                 theTolerance,
1477                 false);
1478 }
1479
1480 //=======================================================================
1481 //function : RotationSweepObjectMakeGroups
1482 //purpose  : 
1483 //=======================================================================
1484
1485 SMESH::ListOfGroups*
1486 SMESH_MeshEditor_i::RotationSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1487                                                   const SMESH::AxisStruct&  theAxis,
1488                                                   CORBA::Double             theAngleInRadians,
1489                                                   CORBA::Long               theNbOfSteps,
1490                                                   CORBA::Double             theTolerance)
1491 {
1492   SMESH::long_array_var anElementsId = theObject->GetIDs();
1493   SMESH::ListOfGroups *aGroups = rotationSweep(anElementsId,
1494                                                theAxis,
1495                                                theAngleInRadians,
1496                                                theNbOfSteps,
1497                                                theTolerance,
1498                                                true);
1499   if ( !myPreviewMode ) {
1500     TPythonDump() << "axis = " << theAxis;
1501     TPythonDump aPythonDump;
1502     DumpGroupsList(aPythonDump,aGroups);
1503     aPythonDump<< this << ".RotationSweepObjectMakeGroups( "
1504                << theObject
1505                << ", axis, "
1506                << theAngleInRadians << ", "
1507                << theNbOfSteps << ", "
1508                << theTolerance << " )";
1509   }
1510   return aGroups;
1511 }
1512
1513
1514 //=======================================================================
1515 //function : extrusionSweep
1516 //purpose  : 
1517 //=======================================================================
1518
1519 SMESH::ListOfGroups*
1520 SMESH_MeshEditor_i::extrusionSweep(const SMESH::long_array & theIDsOfElements,
1521                                    const SMESH::DirStruct &  theStepVector,
1522                                    CORBA::Long               theNbOfSteps,
1523                                    const bool                theMakeGroups,
1524                                    const SMDSAbs_ElementType theElementType)
1525 {
1526   initData();
1527
1528   try {   
1529 #ifdef NO_CAS_CATCH
1530     OCC_CATCH_SIGNALS;
1531 #endif
1532     TIDSortedElemSet elements;
1533     arrayToSet(theIDsOfElements, GetMeshDS(), elements, theElementType);
1534
1535     const SMESH::PointStruct * P = &theStepVector.PS;
1536     gp_Vec stepVec( P->x, P->y, P->z );
1537
1538     TElemOfElemListMap aHystory;
1539     ::SMESH_MeshEditor anEditor( myMesh );
1540     ::SMESH_MeshEditor::PGroupIDs groupIds =
1541         anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory, theMakeGroups);
1542
1543     storeResult(anEditor);
1544
1545     return theMakeGroups ? getGroups(groupIds.get()) : 0;
1546
1547   } catch(Standard_Failure) {
1548     Handle(Standard_Failure) aFail = Standard_Failure::Caught();          
1549     INFOS( "SMESH_MeshEditor_i::ExtrusionSweep fails - "<< aFail->GetMessageString() );
1550   }
1551   return 0;
1552 }
1553
1554 //=======================================================================
1555 //function : ExtrusionSweep
1556 //purpose  :
1557 //=======================================================================
1558
1559 void SMESH_MeshEditor_i::ExtrusionSweep(const SMESH::long_array & theIDsOfElements,
1560                                         const SMESH::DirStruct &  theStepVector,
1561                                         CORBA::Long               theNbOfSteps)
1562 {
1563   extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, false );
1564   if ( !myPreviewMode ) {
1565     TPythonDump() << "stepVector = " << theStepVector;
1566     TPythonDump() << this << ".ExtrusionSweep( "
1567                   << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1568   }
1569 }
1570
1571
1572 //=======================================================================
1573 //function : ExtrusionSweepObject
1574 //purpose  :
1575 //=======================================================================
1576
1577 void SMESH_MeshEditor_i::ExtrusionSweepObject(SMESH::SMESH_IDSource_ptr theObject,
1578                                               const SMESH::DirStruct &  theStepVector,
1579                                               CORBA::Long               theNbOfSteps)
1580 {
1581   SMESH::long_array_var anElementsId = theObject->GetIDs();
1582   extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false );
1583   if ( !myPreviewMode ) {
1584     TPythonDump() << "stepVector = " << theStepVector;
1585     TPythonDump() << this << ".ExtrusionSweepObject( "
1586                   << theObject << ", stepVector, " << theNbOfSteps << " )";
1587   }
1588 }
1589
1590 //=======================================================================
1591 //function : ExtrusionSweepObject1D
1592 //purpose  :
1593 //=======================================================================
1594
1595 void SMESH_MeshEditor_i::ExtrusionSweepObject1D(SMESH::SMESH_IDSource_ptr theObject,
1596                                                 const SMESH::DirStruct &  theStepVector,
1597                                                 CORBA::Long               theNbOfSteps)
1598 {
1599   SMESH::long_array_var anElementsId = theObject->GetIDs();
1600   extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Edge );
1601   if ( !myPreviewMode ) {
1602     TPythonDump() << "stepVector = " << theStepVector;
1603     TPythonDump() << this << ".ExtrusionSweepObject1D( "
1604                   << theObject << ", stepVector, " << theNbOfSteps << " )";
1605   }
1606 }
1607
1608 //=======================================================================
1609 //function : ExtrusionSweepObject2D
1610 //purpose  :
1611 //=======================================================================
1612
1613 void SMESH_MeshEditor_i::ExtrusionSweepObject2D(SMESH::SMESH_IDSource_ptr theObject,
1614                                                 const SMESH::DirStruct &  theStepVector,
1615                                                 CORBA::Long               theNbOfSteps)
1616 {
1617   SMESH::long_array_var anElementsId = theObject->GetIDs();
1618   extrusionSweep (anElementsId, theStepVector, theNbOfSteps, false, SMDSAbs_Face );
1619   if ( !myPreviewMode ) {
1620     TPythonDump() << "stepVector = " << theStepVector;
1621     TPythonDump() << this << ".ExtrusionSweepObject2D( "
1622                   << theObject << ", stepVector, " << theNbOfSteps << " )";
1623   }
1624 }
1625
1626 //=======================================================================
1627 //function : ExtrusionSweepMakeGroups
1628 //purpose  : 
1629 //=======================================================================
1630
1631 SMESH::ListOfGroups*
1632 SMESH_MeshEditor_i::ExtrusionSweepMakeGroups(const SMESH::long_array& theIDsOfElements,
1633                                              const SMESH::DirStruct&  theStepVector,
1634                                              CORBA::Long              theNbOfSteps)
1635 {
1636   SMESH::ListOfGroups* aGroups = extrusionSweep (theIDsOfElements, theStepVector, theNbOfSteps, true );
1637     
1638   if ( !myPreviewMode ) {
1639     TPythonDump() << "stepVector = " << theStepVector;
1640     TPythonDump aPythonDump;
1641     DumpGroupsList(aPythonDump,aGroups);
1642     aPythonDump  << this << ".ExtrusionSweepMakeGroups( "
1643                  << theIDsOfElements << ", stepVector, " << theNbOfSteps << " )";
1644   }
1645   return aGroups;
1646 }
1647 //=======================================================================
1648 //function : ExtrusionSweepObjectMakeGroups
1649 //purpose  : 
1650 //=======================================================================
1651
1652 SMESH::ListOfGroups*
1653 SMESH_MeshEditor_i::ExtrusionSweepObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1654                                                    const SMESH::DirStruct&   theStepVector,
1655                                                    CORBA::Long               theNbOfSteps)
1656 {
1657   SMESH::long_array_var anElementsId = theObject->GetIDs();
1658   SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true );
1659   
1660   if ( !myPreviewMode ) {
1661     TPythonDump() << "stepVector = " << theStepVector;
1662     TPythonDump aPythonDump;
1663     DumpGroupsList(aPythonDump,aGroups);
1664     aPythonDump<< this << ".ExtrusionSweepObjectMakeGroups( "
1665                << theObject << ", stepVector, " << theNbOfSteps << " )";
1666   }
1667   return aGroups;
1668 }
1669
1670 //=======================================================================
1671 //function : ExtrusionSweepObject1DMakeGroups
1672 //purpose  : 
1673 //=======================================================================
1674
1675 SMESH::ListOfGroups*
1676 SMESH_MeshEditor_i::ExtrusionSweepObject1DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1677                                                      const SMESH::DirStruct&   theStepVector,
1678                                                      CORBA::Long               theNbOfSteps)
1679 {
1680   SMESH::long_array_var anElementsId = theObject->GetIDs();
1681   SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Edge );
1682   if ( !myPreviewMode ) {
1683     TPythonDump() << "stepVector = " << theStepVector;
1684     TPythonDump aPythonDump;
1685     DumpGroupsList(aPythonDump,aGroups);
1686     aPythonDump << this << ".ExtrusionSweepObject1DMakeGroups( "
1687                 << theObject << ", stepVector, " << theNbOfSteps << " )";
1688   }
1689   return aGroups;
1690 }
1691
1692 //=======================================================================
1693 //function : ExtrusionSweepObject2DMakeGroups
1694 //purpose  : 
1695 //=======================================================================
1696
1697 SMESH::ListOfGroups*
1698 SMESH_MeshEditor_i::ExtrusionSweepObject2DMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
1699                                                      const SMESH::DirStruct&   theStepVector,
1700                                                      CORBA::Long               theNbOfSteps)
1701 {
1702   SMESH::long_array_var anElementsId = theObject->GetIDs();
1703   SMESH::ListOfGroups * aGroups = extrusionSweep (anElementsId, theStepVector, theNbOfSteps, true, SMDSAbs_Face );
1704   if ( !myPreviewMode ) {
1705     TPythonDump() << "stepVector = " << theStepVector;
1706     TPythonDump aPythonDump;
1707     DumpGroupsList(aPythonDump,aGroups);
1708     aPythonDump << this << ".ExtrusionSweepObject2DMakeGroups( "
1709                 << theObject << ", stepVector, " << theNbOfSteps << " )";
1710   }
1711   return aGroups;
1712 }
1713
1714
1715 //=======================================================================
1716 //function : advancedExtrusion
1717 //purpose  : 
1718 //=======================================================================
1719
1720 SMESH::ListOfGroups*
1721 SMESH_MeshEditor_i::advancedExtrusion(const SMESH::long_array & theIDsOfElements,
1722                                       const SMESH::DirStruct &  theStepVector,
1723                                       CORBA::Long               theNbOfSteps,
1724                                       CORBA::Long               theExtrFlags,
1725                                       CORBA::Double             theSewTolerance,
1726                                       const bool                theMakeGroups)
1727 {
1728   initData();
1729
1730   TIDSortedElemSet elements;
1731   arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1732
1733   const SMESH::PointStruct * P = &theStepVector.PS;
1734   gp_Vec stepVec( P->x, P->y, P->z );
1735
1736   ::SMESH_MeshEditor anEditor( myMesh );
1737   TElemOfElemListMap aHystory;
1738   ::SMESH_MeshEditor::PGroupIDs groupIds =
1739       anEditor.ExtrusionSweep (elements, stepVec, theNbOfSteps, aHystory,
1740                                theMakeGroups, theExtrFlags, theSewTolerance);
1741   storeResult(anEditor);
1742
1743   return theMakeGroups ? getGroups(groupIds.get()) : 0;
1744 }
1745
1746 //=======================================================================
1747 //function : AdvancedExtrusion
1748 //purpose  :
1749 //=======================================================================
1750
1751 void SMESH_MeshEditor_i::AdvancedExtrusion(const SMESH::long_array & theIDsOfElements,
1752                                            const SMESH::DirStruct &  theStepVector,
1753                                            CORBA::Long               theNbOfSteps,
1754                                            CORBA::Long               theExtrFlags,
1755                                            CORBA::Double             theSewTolerance)
1756 {
1757   if ( !myPreviewMode ) {
1758     TPythonDump() << "stepVector = " << theStepVector;
1759     TPythonDump() << this << ".AdvancedExtrusion("
1760                   << theIDsOfElements
1761                   << ", stepVector, "
1762                   << theNbOfSteps << ","
1763                   << theExtrFlags << ", "
1764                   << theSewTolerance <<  " )";
1765   }
1766   advancedExtrusion( theIDsOfElements,
1767                      theStepVector,
1768                      theNbOfSteps,
1769                      theExtrFlags,
1770                      theSewTolerance,
1771                      false);
1772 }
1773
1774 //=======================================================================
1775 //function : AdvancedExtrusionMakeGroups
1776 //purpose  : 
1777 //=======================================================================
1778
1779 SMESH::ListOfGroups*
1780 SMESH_MeshEditor_i::AdvancedExtrusionMakeGroups(const SMESH::long_array& theIDsOfElements,
1781                                                 const SMESH::DirStruct&  theStepVector,
1782                                                 CORBA::Long              theNbOfSteps,
1783                                                 CORBA::Long              theExtrFlags,
1784                                                 CORBA::Double            theSewTolerance)
1785 {
1786   SMESH::ListOfGroups * aGroups = advancedExtrusion( theIDsOfElements,
1787                                                     theStepVector,
1788                                                     theNbOfSteps,
1789                                                     theExtrFlags,
1790                                                     theSewTolerance,
1791                                                     true);
1792   
1793   if ( !myPreviewMode ) {
1794     TPythonDump() << "stepVector = " << theStepVector;
1795     TPythonDump aPythonDump;
1796     DumpGroupsList(aPythonDump,aGroups);
1797     aPythonDump << this << ".AdvancedExtrusionMakeGroups("
1798                 << theIDsOfElements
1799                 << ", stepVector, "
1800                 << theNbOfSteps << ","
1801                 << theExtrFlags << ", "
1802                 << theSewTolerance <<  " )";
1803   }
1804   return aGroups;
1805 }
1806
1807
1808 //================================================================================
1809 /*!
1810  * \brief Convert extrusion error to IDL enum
1811  */
1812 //================================================================================
1813
1814 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
1815
1816 static SMESH::SMESH_MeshEditor::Extrusion_Error convExtrError( const::SMESH_MeshEditor::Extrusion_Error e )
1817 {
1818   switch ( e ) {
1819   RETCASE( EXTR_OK );
1820   RETCASE( EXTR_NO_ELEMENTS );
1821   RETCASE( EXTR_PATH_NOT_EDGE );
1822   RETCASE( EXTR_BAD_PATH_SHAPE );
1823   RETCASE( EXTR_BAD_STARTING_NODE );
1824   RETCASE( EXTR_BAD_ANGLES_NUMBER );
1825   RETCASE( EXTR_CANT_GET_TANGENT );
1826   }
1827   return SMESH::SMESH_MeshEditor::EXTR_OK;
1828 }
1829
1830
1831 //=======================================================================
1832 //function : extrusionAlongPath
1833 //purpose  : 
1834 //=======================================================================
1835
1836 SMESH::ListOfGroups*
1837 SMESH_MeshEditor_i::extrusionAlongPath(const SMESH::long_array &   theIDsOfElements,
1838                                        SMESH::SMESH_Mesh_ptr       thePathMesh,
1839                                        GEOM::GEOM_Object_ptr       thePathShape,
1840                                        CORBA::Long                 theNodeStart,
1841                                        CORBA::Boolean              theHasAngles,
1842                                        const SMESH::double_array & theAngles,
1843                                        CORBA::Boolean              theHasRefPoint,
1844                                        const SMESH::PointStruct &  theRefPoint,
1845                                        const bool                  theMakeGroups,
1846                                        SMESH::SMESH_MeshEditor::Extrusion_Error & theError)
1847 {
1848   initData();
1849
1850   if ( thePathMesh->_is_nil() || thePathShape->_is_nil() ) {
1851     theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1852     return 0;
1853   }
1854   SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
1855
1856   TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
1857   SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
1858
1859   if ( !aSubMesh || !aSubMesh->GetSubMeshDS()) {
1860     theError = SMESH::SMESH_MeshEditor::EXTR_BAD_PATH_SHAPE;
1861     return 0;
1862   }
1863
1864   SMDS_MeshNode* nodeStart = (SMDS_MeshNode*)aMeshImp->GetImpl().GetMeshDS()->FindNode(theNodeStart);
1865   if ( !nodeStart ) {
1866     theError = SMESH::SMESH_MeshEditor::EXTR_BAD_STARTING_NODE;
1867     return 0;
1868   }
1869
1870   TIDSortedElemSet elements;
1871   arrayToSet(theIDsOfElements, GetMeshDS(), elements);
1872
1873   list<double> angles;
1874   for (int i = 0; i < theAngles.length(); i++) {
1875     angles.push_back( theAngles[i] );
1876   }
1877
1878   gp_Pnt refPnt( theRefPoint.x, theRefPoint.y, theRefPoint.z );
1879
1880   int nbOldGroups = myMesh->NbGroup();
1881
1882   ::SMESH_MeshEditor anEditor( myMesh );
1883   ::SMESH_MeshEditor::Extrusion_Error error =
1884       anEditor.ExtrusionAlongTrack( elements, aSubMesh, nodeStart,
1885                                     theHasAngles, angles,
1886                                     theHasRefPoint, refPnt, theMakeGroups );
1887   storeResult(anEditor);
1888   theError = convExtrError( error );
1889
1890   if ( theMakeGroups ) {
1891     list<int> groupIDs = myMesh->GetGroupIds();
1892     list<int>::iterator newBegin = groupIDs.begin();
1893     std::advance( newBegin, nbOldGroups ); // skip old groups
1894     groupIDs.erase( groupIDs.begin(), newBegin );
1895     return getGroups( & groupIDs );
1896   }
1897   return 0;
1898 }
1899
1900 //=======================================================================
1901 //function : ExtrusionAlongPath
1902 //purpose  :
1903 //=======================================================================
1904
1905 SMESH::SMESH_MeshEditor::Extrusion_Error
1906   SMESH_MeshEditor_i::ExtrusionAlongPath(const SMESH::long_array &   theIDsOfElements,
1907                                          SMESH::SMESH_Mesh_ptr       thePathMesh,
1908                                          GEOM::GEOM_Object_ptr       thePathShape,
1909                                          CORBA::Long                 theNodeStart,
1910                                          CORBA::Boolean              theHasAngles,
1911                                          const SMESH::double_array & theAngles,
1912                                          CORBA::Boolean              theHasRefPoint,
1913                                          const SMESH::PointStruct &  theRefPoint)
1914 {
1915   if ( !myPreviewMode ) {
1916     TPythonDump() << "rotAngles = " << theAngles;
1917
1918     if ( theHasRefPoint )
1919       TPythonDump() << "refPoint = SMESH.PointStruct( "
1920                     << theRefPoint.x << ", "
1921                     << theRefPoint.y << ", "
1922                     << theRefPoint.z << " )";
1923     else
1924       TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1925
1926     TPythonDump() << "error = " << this << ".ExtrusionAlongPath( "
1927                   << theIDsOfElements << ", "
1928                   << thePathMesh      << ", "
1929                   << thePathShape     << ", "
1930                   << theNodeStart     << ", "
1931                   << theHasAngles     << ", "
1932                   << "rotAngles"      << ", "
1933                   << theHasRefPoint   << ", refPoint )";
1934   }
1935   SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1936   extrusionAlongPath( theIDsOfElements,
1937                       thePathMesh,
1938                       thePathShape,
1939                       theNodeStart,
1940                       theHasAngles,
1941                       theAngles,
1942                       theHasRefPoint,
1943                       theRefPoint,
1944                       false,
1945                       anError);
1946   return anError;
1947 }
1948
1949 //=======================================================================
1950 //function : ExtrusionAlongPathObject
1951 //purpose  :
1952 //=======================================================================
1953
1954 SMESH::SMESH_MeshEditor::Extrusion_Error
1955 SMESH_MeshEditor_i::ExtrusionAlongPathObject(SMESH::SMESH_IDSource_ptr   theObject,
1956                                              SMESH::SMESH_Mesh_ptr       thePathMesh,
1957                                              GEOM::GEOM_Object_ptr       thePathShape,
1958                                              CORBA::Long                 theNodeStart,
1959                                              CORBA::Boolean              theHasAngles,
1960                                              const SMESH::double_array & theAngles,
1961                                              CORBA::Boolean              theHasRefPoint,
1962                                              const SMESH::PointStruct &  theRefPoint)
1963 {
1964   if ( !myPreviewMode ) {
1965     TPythonDump() << "rotAngles = " << theAngles;
1966
1967     if ( theHasRefPoint )
1968       TPythonDump() << "refPoint = SMESH.PointStruct( "
1969                     << theRefPoint.x << ", "
1970                     << theRefPoint.y << ", "
1971                     << theRefPoint.z << " )";
1972     else
1973       TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
1974
1975     TPythonDump() << "error = " << this << ".ExtrusionAlongPathObject( "
1976                   << theObject        << ", "
1977                   << thePathMesh      << ", "
1978                   << thePathShape     << ", "
1979                   << theNodeStart     << ", "
1980                   << theHasAngles     << ", "
1981                   << "rotAngles"      << ", "
1982                   << theHasRefPoint   << ", refPoint )";
1983   }
1984   SMESH::SMESH_MeshEditor::Extrusion_Error anError;
1985   SMESH::long_array_var anElementsId = theObject->GetIDs();
1986   extrusionAlongPath( anElementsId,
1987                       thePathMesh,
1988                       thePathShape,
1989                       theNodeStart,
1990                       theHasAngles,
1991                       theAngles,
1992                       theHasRefPoint,
1993                       theRefPoint,
1994                       false,
1995                       anError);
1996   return anError;
1997 }
1998
1999
2000 //=======================================================================
2001 //function : ExtrusionAlongPathMakeGroups
2002 //purpose  : 
2003 //=======================================================================
2004
2005 SMESH::ListOfGroups*
2006 SMESH_MeshEditor_i::ExtrusionAlongPathMakeGroups(const SMESH::long_array&   theIDsOfElements,
2007                                                  SMESH::SMESH_Mesh_ptr      thePathMesh,
2008                                                  GEOM::GEOM_Object_ptr      thePathShape,
2009                                                  CORBA::Long                theNodeStart,
2010                                                  CORBA::Boolean             theHasAngles,
2011                                                  const SMESH::double_array& theAngles,
2012                                                  CORBA::Boolean             theHasRefPoint,
2013                                                  const SMESH::PointStruct&  theRefPoint,
2014                                                  SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2015 {
2016     SMESH::ListOfGroups * aGroups =  extrusionAlongPath( theIDsOfElements,
2017                                                          thePathMesh,
2018                                                          thePathShape,
2019                                                          theNodeStart,
2020                                                          theHasAngles,
2021                                                          theAngles,
2022                                                          theHasRefPoint,
2023                                                          theRefPoint,
2024                                                          true,
2025                                                          Error);
2026   if ( !myPreviewMode ) {
2027     TPythonDump() << "rotAngles = " << theAngles;
2028
2029     if ( theHasRefPoint )
2030       TPythonDump() << "refPoint = SMESH.PointStruct( "
2031                     << theRefPoint.x << ", "
2032                     << theRefPoint.y << ", "
2033                     << theRefPoint.z << " )";
2034     else
2035       TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2036
2037     bool isDumpGroups = aGroups && aGroups->length() > 0;
2038     TPythonDump aPythonDump;
2039     if(isDumpGroups) {
2040       aPythonDump << "("<<aGroups;
2041     }
2042     if(isDumpGroups)
2043       aPythonDump << ", error)";
2044     else
2045       aPythonDump <<"error";
2046     
2047     aPythonDump<<" = "<< this << ".ExtrusionAlongPathMakeGroups( "
2048                << theIDsOfElements << ", "
2049                << thePathMesh      << ", "
2050                << thePathShape     << ", "
2051                << theNodeStart     << ", "
2052                << theHasAngles     << ", "
2053                << "rotAngles"      << ", "
2054                << theHasRefPoint   << ", refPoint )";
2055   }
2056   return aGroups;
2057 }
2058
2059 //=======================================================================
2060 //function : ExtrusionAlongPathObjectMakeGroups
2061 //purpose  : 
2062 //=======================================================================
2063
2064 SMESH::ListOfGroups* SMESH_MeshEditor_i::
2065 ExtrusionAlongPathObjectMakeGroups(SMESH::SMESH_IDSource_ptr  theObject,
2066                                    SMESH::SMESH_Mesh_ptr      thePathMesh,
2067                                    GEOM::GEOM_Object_ptr      thePathShape,
2068                                    CORBA::Long                theNodeStart,
2069                                    CORBA::Boolean             theHasAngles,
2070                                    const SMESH::double_array& theAngles,
2071                                    CORBA::Boolean             theHasRefPoint,
2072                                    const SMESH::PointStruct&  theRefPoint,
2073                                    SMESH::SMESH_MeshEditor::Extrusion_Error& Error)
2074 {
2075   SMESH::long_array_var anElementsId = theObject->GetIDs();
2076   SMESH::ListOfGroups * aGroups = extrusionAlongPath( anElementsId,
2077                                                       thePathMesh,
2078                                                       thePathShape,
2079                                                       theNodeStart,
2080                                                       theHasAngles,
2081                                                       theAngles,
2082                                                       theHasRefPoint,
2083                                                       theRefPoint,
2084                                                       true,
2085                                                       Error);
2086   
2087   if ( !myPreviewMode ) {
2088     TPythonDump() << "rotAngles = " << theAngles;
2089
2090     if ( theHasRefPoint )
2091       TPythonDump() << "refPoint = SMESH.PointStruct( "
2092                     << theRefPoint.x << ", "
2093                     << theRefPoint.y << ", "
2094                     << theRefPoint.z << " )";
2095     else
2096       TPythonDump() << "refPoint = SMESH.PointStruct( 0,0,0 )";
2097     
2098     bool isDumpGroups = aGroups && aGroups->length() > 0;
2099     TPythonDump aPythonDump;
2100     if(isDumpGroups) {
2101       aPythonDump << "("<<aGroups;
2102     }
2103     if(isDumpGroups)
2104       aPythonDump << ", error)";
2105     else
2106       aPythonDump <<"error";
2107
2108     aPythonDump << " = " << this << ".ExtrusionAlongPathObjectMakeGroups( "
2109                 << theObject << ", "
2110                 << thePathMesh      << ", "
2111                 << thePathShape     << ", "
2112                 << theNodeStart     << ", "
2113                 << theHasAngles     << ", "
2114                 << "rotAngles"      << ", "
2115                 << theHasRefPoint   << ", refPoint )";
2116   }
2117   return aGroups;
2118 }
2119
2120 //================================================================================
2121 /*!
2122  * \brief Compute rotation angles for ExtrusionAlongPath as linear variation
2123  * of given angles along path steps
2124   * \param PathMesh mesh containing a 1D sub-mesh on the edge, along 
2125   *                which proceeds the extrusion
2126   * \param PathShape is shape(edge); as the mesh can be complex, the edge 
2127   *                 is used to define the sub-mesh for the path
2128  */
2129 //================================================================================
2130
2131 SMESH::double_array*
2132 SMESH_MeshEditor_i::LinearAnglesVariation(SMESH::SMESH_Mesh_ptr       thePathMesh,
2133                                           GEOM::GEOM_Object_ptr       thePathShape,
2134                                           const SMESH::double_array & theAngles)
2135 {
2136   SMESH::double_array_var aResult = new SMESH::double_array();
2137   int nbAngles = theAngles.length();
2138   if ( nbAngles > 0 && !thePathMesh->_is_nil() && !thePathShape->_is_nil() )
2139   {
2140     SMESH_Mesh_i* aMeshImp = SMESH::DownCast<SMESH_Mesh_i*>( thePathMesh );
2141     TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( thePathShape );
2142     SMESH_subMesh* aSubMesh = aMeshImp->GetImpl().GetSubMesh( aShape );
2143     if ( !aSubMesh || !aSubMesh->GetSubMeshDS())
2144       return aResult._retn();
2145     int nbSteps = aSubMesh->GetSubMeshDS()->NbElements();
2146     if ( nbSteps == nbAngles )
2147     {
2148       aResult.inout() = theAngles;
2149     }
2150     else
2151     {
2152       aResult->length( nbSteps );
2153       double rAn2St = double( nbAngles ) / double( nbSteps );
2154       double angPrev = 0, angle;
2155       for ( int iSt = 0; iSt < nbSteps; ++iSt )
2156       {
2157         double angCur = rAn2St * ( iSt+1 );
2158         double angCurFloor  = floor( angCur );
2159         double angPrevFloor = floor( angPrev );
2160         if ( angPrevFloor == angCurFloor )
2161           angle = rAn2St * theAngles[ int( angCurFloor ) ];
2162         else
2163         {
2164           int iP = int( angPrevFloor );
2165           double angPrevCeil = ceil(angPrev);
2166           angle = ( angPrevCeil - angPrev ) * theAngles[ iP ];
2167           
2168           int iC = int( angCurFloor );
2169           if ( iC < nbAngles )
2170             angle += ( angCur - angCurFloor ) * theAngles[ iC ];
2171
2172           iP = int( angPrevCeil );
2173           while ( iC-- > iP )
2174             angle += theAngles[ iC ];
2175         }
2176         aResult[ iSt ] = angle;
2177         angPrev = angCur;
2178       }
2179     }
2180   }
2181   // Update Python script
2182   TPythonDump() << "rotAngles = " << theAngles;
2183   TPythonDump() << "rotAngles = " << this << ".LinearAnglesVariation( "
2184                 << thePathMesh  << ", "
2185                 << thePathShape << ", "
2186                 << "rotAngles )";
2187
2188   return aResult._retn();
2189 }
2190
2191
2192 //=======================================================================
2193 //function : mirror
2194 //purpose  : 
2195 //=======================================================================
2196
2197 SMESH::ListOfGroups*
2198 SMESH_MeshEditor_i::mirror(const SMESH::long_array &           theIDsOfElements,
2199                            const SMESH::AxisStruct &           theAxis,
2200                            SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2201                            CORBA::Boolean                      theCopy,
2202                            const bool                          theMakeGroups,
2203                            ::SMESH_Mesh*                       theTargetMesh)
2204 {
2205   initData();
2206
2207   TIDSortedElemSet elements;
2208   arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2209
2210   gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2211   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2212
2213   gp_Trsf aTrsf;
2214   switch ( theMirrorType ) {
2215   case  SMESH::SMESH_MeshEditor::POINT:
2216     aTrsf.SetMirror( P );
2217     break;
2218   case  SMESH::SMESH_MeshEditor::AXIS:
2219     aTrsf.SetMirror( gp_Ax1( P, V ));
2220     break;
2221   default:
2222     aTrsf.SetMirror( gp_Ax2( P, V ));
2223   }
2224
2225   ::SMESH_MeshEditor anEditor( myMesh );
2226   ::SMESH_MeshEditor::PGroupIDs groupIds =
2227       anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2228
2229   if(theCopy) {
2230     storeResult(anEditor);
2231   }
2232   return theMakeGroups ? getGroups(groupIds.get()) : 0;
2233 }
2234
2235 //=======================================================================
2236 //function : Mirror
2237 //purpose  :
2238 //=======================================================================
2239
2240 void SMESH_MeshEditor_i::Mirror(const SMESH::long_array &           theIDsOfElements,
2241                                 const SMESH::AxisStruct &           theAxis,
2242                                 SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2243                                 CORBA::Boolean                      theCopy)
2244 {
2245   if ( !myPreviewMode ) {
2246     TPythonDump() << this << ".Mirror( "
2247                   << theIDsOfElements << ", "
2248                   << theAxis          << ", "
2249                   << mirrorTypeName(theMirrorType) << ", "
2250                   << theCopy          << " )";
2251   }
2252   mirror(theIDsOfElements, theAxis, theMirrorType, theCopy, false);
2253 }
2254
2255
2256 //=======================================================================
2257 //function : MirrorObject
2258 //purpose  :
2259 //=======================================================================
2260
2261 void SMESH_MeshEditor_i::MirrorObject(SMESH::SMESH_IDSource_ptr           theObject,
2262                                       const SMESH::AxisStruct &           theAxis,
2263                                       SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2264                                       CORBA::Boolean                      theCopy)
2265 {
2266   if ( !myPreviewMode ) {
2267     TPythonDump() << this << ".MirrorObject( "
2268                   << theObject << ", "
2269                   << theAxis   << ", "
2270                   << mirrorTypeName(theMirrorType) << ", "
2271                   << theCopy   << " )";
2272   }
2273   SMESH::long_array_var anElementsId = theObject->GetIDs();
2274   mirror(anElementsId, theAxis, theMirrorType, theCopy, false);
2275 }
2276
2277 //=======================================================================
2278 //function : MirrorMakeGroups
2279 //purpose  : 
2280 //=======================================================================
2281
2282 SMESH::ListOfGroups*
2283 SMESH_MeshEditor_i::MirrorMakeGroups(const SMESH::long_array&            theIDsOfElements,
2284                                      const SMESH::AxisStruct&            theMirror,
2285                                      SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2286 {
2287   SMESH::ListOfGroups * aGroups = mirror(theIDsOfElements, theMirror, theMirrorType, true, true);
2288   if ( !myPreviewMode ) {
2289     TPythonDump()<<"axis = "<<theMirror;
2290     TPythonDump aPythonDump;
2291     DumpGroupsList(aPythonDump,aGroups);
2292     aPythonDump << this << ".MirrorMakeGroups( "
2293                 << theIDsOfElements << ", "
2294                 << "axis, "
2295                 << mirrorTypeName(theMirrorType) << " )";
2296   }
2297   return aGroups;
2298 }
2299
2300 //=======================================================================
2301 //function : MirrorObjectMakeGroups
2302 //purpose  : 
2303 //=======================================================================
2304
2305 SMESH::ListOfGroups*
2306 SMESH_MeshEditor_i::MirrorObjectMakeGroups(SMESH::SMESH_IDSource_ptr           theObject,
2307                                            const SMESH::AxisStruct&            theMirror,
2308                                            SMESH::SMESH_MeshEditor::MirrorType theMirrorType)
2309 {
2310   SMESH::long_array_var anElementsId = theObject->GetIDs();
2311   SMESH::ListOfGroups * aGroups = mirror(anElementsId, theMirror, theMirrorType, true, true);
2312   if ( !myPreviewMode ) {
2313     TPythonDump()<<"axis = "<<theMirror;
2314     TPythonDump aPythonDump;
2315     DumpGroupsList(aPythonDump,aGroups);
2316     aPythonDump << this << ".MirrorObjectMakeGroups( "
2317                 << theObject << ", "
2318                 << "axis, "
2319                 << mirrorTypeName(theMirrorType) << " )";
2320   }
2321   return aGroups;
2322 }
2323
2324 //=======================================================================
2325 //function : MirrorMakeMesh
2326 //purpose  : 
2327 //=======================================================================
2328
2329 SMESH::SMESH_Mesh_ptr
2330 SMESH_MeshEditor_i::MirrorMakeMesh(const SMESH::long_array&            theIDsOfElements,
2331                                    const SMESH::AxisStruct&            theMirror,
2332                                    SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2333                                    CORBA::Boolean                      theCopyGroups,
2334                                    const char*                         theMeshName)
2335 {
2336   SMESH_Mesh_i* mesh_i;
2337   SMESH::SMESH_Mesh_var mesh;
2338   { // open new scope to dump "MakeMesh" command
2339     // and then "GetGroups" using SMESH_Mesh::GetGroups()
2340     
2341     TPythonDump pydump; // to prevent dump at mesh creation
2342
2343     mesh = makeMesh( theMeshName );
2344     mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2345     if (mesh_i) {
2346       mirror(theIDsOfElements, theMirror, theMirrorType,
2347              false, theCopyGroups, & mesh_i->GetImpl());
2348       mesh_i->CreateGroupServants();
2349     }
2350     
2351     if ( !myPreviewMode ) {
2352       pydump << mesh << " = " << this << ".MirrorMakeMesh( "
2353              << theIDsOfElements << ", "
2354              << theMirror   << ", "
2355              << mirrorTypeName(theMirrorType) << ", "
2356              << theCopyGroups << ", '"
2357              << theMeshName << "' )";
2358     }
2359   }
2360
2361   //dump "GetGroups"
2362   if(!myPreviewMode && mesh_i)
2363     mesh_i->GetGroups();
2364   
2365   return mesh._retn();
2366 }
2367
2368 //=======================================================================
2369 //function : MirrorObjectMakeMesh
2370 //purpose  : 
2371 //=======================================================================
2372
2373 SMESH::SMESH_Mesh_ptr
2374 SMESH_MeshEditor_i::MirrorObjectMakeMesh(SMESH::SMESH_IDSource_ptr           theObject,
2375                                          const SMESH::AxisStruct&            theMirror,
2376                                          SMESH::SMESH_MeshEditor::MirrorType theMirrorType,
2377                                          CORBA::Boolean                      theCopyGroups,
2378                                          const char*                         theMeshName)
2379 {
2380   SMESH_Mesh_i* mesh_i;
2381   SMESH::SMESH_Mesh_var mesh;
2382   { // open new scope to dump "MakeMesh" command
2383     // and then "GetGroups" using SMESH_Mesh::GetGroups()
2384     
2385     TPythonDump pydump; // to prevent dump at mesh creation
2386
2387     mesh = makeMesh( theMeshName );
2388     mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2389     if ( mesh_i ) {
2390       SMESH::long_array_var anElementsId = theObject->GetIDs();
2391       mirror(anElementsId, theMirror, theMirrorType,
2392              false, theCopyGroups, & mesh_i->GetImpl());
2393       mesh_i->CreateGroupServants();
2394     }
2395
2396     if ( !myPreviewMode ) {
2397       pydump << mesh << " = " << this << ".MirrorObjectMakeMesh( "
2398              << theObject << ", "
2399              << theMirror   << ", "
2400              << mirrorTypeName(theMirrorType) << ", "
2401              << theCopyGroups << ", '"
2402              << theMeshName << "' )";
2403     }
2404   } 
2405
2406   //dump "GetGroups"
2407   if(!myPreviewMode && mesh_i)
2408     mesh_i->GetGroups();
2409   
2410   return mesh._retn();
2411 }
2412
2413 //=======================================================================
2414 //function : translate
2415 //purpose  : 
2416 //=======================================================================
2417
2418 SMESH::ListOfGroups*
2419 SMESH_MeshEditor_i::translate(const SMESH::long_array & theIDsOfElements,
2420                               const SMESH::DirStruct &  theVector,
2421                               CORBA::Boolean            theCopy,
2422                               const bool                theMakeGroups,
2423                               ::SMESH_Mesh*             theTargetMesh)
2424 {
2425   initData();
2426
2427   TIDSortedElemSet elements;
2428   arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2429
2430   gp_Trsf aTrsf;
2431   const SMESH::PointStruct * P = &theVector.PS;
2432   aTrsf.SetTranslation( gp_Vec( P->x, P->y, P->z ));
2433
2434   ::SMESH_MeshEditor anEditor( myMesh );
2435   ::SMESH_MeshEditor::PGroupIDs groupIds =
2436       anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2437
2438   if(theCopy)
2439     storeResult(anEditor);
2440
2441   return theMakeGroups ? getGroups(groupIds.get()) : 0;
2442 }
2443
2444 //=======================================================================
2445 //function : Translate
2446 //purpose  :
2447 //=======================================================================
2448
2449 void SMESH_MeshEditor_i::Translate(const SMESH::long_array & theIDsOfElements,
2450                                    const SMESH::DirStruct &  theVector,
2451                                    CORBA::Boolean            theCopy)
2452 {
2453   if ( !myPreviewMode ) {
2454     TPythonDump() << "vector = " << theVector;
2455     TPythonDump() << this << ".Translate( "
2456                   << theIDsOfElements
2457                   << ", vector, "
2458                   << theCopy << " )";
2459   }
2460   translate(theIDsOfElements,
2461             theVector,
2462             theCopy,
2463             false);
2464 }
2465
2466 //=======================================================================
2467 //function : TranslateObject
2468 //purpose  :
2469 //=======================================================================
2470
2471 void SMESH_MeshEditor_i::TranslateObject(SMESH::SMESH_IDSource_ptr theObject,
2472                                          const SMESH::DirStruct &  theVector,
2473                                          CORBA::Boolean            theCopy)
2474 {
2475   if ( !myPreviewMode ) {
2476     TPythonDump() << this << ".TranslateObject( "
2477                   << theObject
2478                   << ", vector, "
2479                   << theCopy << " )";
2480   }
2481   SMESH::long_array_var anElementsId = theObject->GetIDs();
2482   translate(anElementsId,
2483             theVector,
2484             theCopy,
2485             false);
2486 }
2487
2488 //=======================================================================
2489 //function : TranslateMakeGroups
2490 //purpose  : 
2491 //=======================================================================
2492
2493 SMESH::ListOfGroups*
2494 SMESH_MeshEditor_i::TranslateMakeGroups(const SMESH::long_array& theIDsOfElements,
2495                                         const SMESH::DirStruct&  theVector)
2496 {
2497   SMESH::ListOfGroups * aGroups = translate(theIDsOfElements,theVector,true,true);
2498   if ( !myPreviewMode ) {
2499     TPythonDump() << "vector = " << theVector;
2500     TPythonDump aPythonDump;
2501     DumpGroupsList(aPythonDump,aGroups);
2502     aPythonDump << this << ".TranslateMakeGroups( "
2503                 << theIDsOfElements
2504                 << ", vector )";
2505   }
2506   return aGroups;
2507 }
2508
2509 //=======================================================================
2510 //function : TranslateObjectMakeGroups
2511 //purpose  : 
2512 //=======================================================================
2513
2514 SMESH::ListOfGroups*
2515 SMESH_MeshEditor_i::TranslateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2516                                               const SMESH::DirStruct&   theVector)
2517 {
2518   SMESH::long_array_var anElementsId = theObject->GetIDs();
2519   SMESH::ListOfGroups * aGroups = translate(anElementsId, theVector, true, true);
2520   
2521   if ( !myPreviewMode ) {
2522
2523     TPythonDump() << "vector = " << theVector;
2524     TPythonDump aPythonDump;
2525     DumpGroupsList(aPythonDump,aGroups);
2526     aPythonDump << this << ".TranslateObjectMakeGroups( "
2527                 << theObject
2528                 << ", vector )";
2529   }
2530   return aGroups;
2531 }
2532
2533 //=======================================================================
2534 //function : TranslateMakeMesh
2535 //purpose  : 
2536 //=======================================================================
2537
2538 SMESH::SMESH_Mesh_ptr
2539 SMESH_MeshEditor_i::TranslateMakeMesh(const SMESH::long_array& theIDsOfElements,
2540                                       const SMESH::DirStruct&  theVector,
2541                                       CORBA::Boolean           theCopyGroups,
2542                                       const char*              theMeshName)
2543 {
2544   SMESH_Mesh_i* mesh_i;
2545   SMESH::SMESH_Mesh_var mesh;
2546   
2547   { // open new scope to dump "MakeMesh" command
2548     // and then "GetGroups" using SMESH_Mesh::GetGroups()
2549
2550     TPythonDump pydump; // to prevent dump at mesh creation
2551     
2552     mesh = makeMesh( theMeshName );
2553     mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2554     
2555     if ( mesh_i ) {
2556       translate(theIDsOfElements, theVector,
2557                 false, theCopyGroups, & mesh_i->GetImpl());
2558       mesh_i->CreateGroupServants();
2559     }
2560     
2561     if ( !myPreviewMode ) {
2562       pydump << mesh << " = " << this << ".TranslateMakeMesh( "
2563              << theIDsOfElements << ", "
2564              << theVector   << ", "
2565              << theCopyGroups << ", '"
2566              << theMeshName << "' )";
2567     }
2568   }
2569   
2570   //dump "GetGroups"
2571   if(!myPreviewMode && mesh_i)
2572     mesh_i->GetGroups();
2573   
2574   return mesh._retn();
2575 }
2576
2577 //=======================================================================
2578 //function : TranslateObjectMakeMesh
2579 //purpose  : 
2580 //=======================================================================
2581
2582 SMESH::SMESH_Mesh_ptr
2583 SMESH_MeshEditor_i::TranslateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2584                                             const SMESH::DirStruct&   theVector,
2585                                             CORBA::Boolean            theCopyGroups,
2586                                             const char*               theMeshName)
2587 {
2588   SMESH_Mesh_i* mesh_i;
2589   SMESH::SMESH_Mesh_var mesh;
2590   { // open new scope to dump "MakeMesh" command
2591     // and then "GetGroups" using SMESH_Mesh::GetGroups()
2592     
2593     TPythonDump pydump; // to prevent dump at mesh creation
2594     mesh = makeMesh( theMeshName );
2595     mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2596     
2597     if ( mesh_i ) {
2598       SMESH::long_array_var anElementsId = theObject->GetIDs();
2599       translate(anElementsId, theVector,
2600                 false, theCopyGroups, & mesh_i->GetImpl());
2601       mesh_i->CreateGroupServants();
2602     }
2603     if ( !myPreviewMode ) {
2604       pydump << mesh << " = " << this << ".TranslateObjectMakeMesh( "
2605              << theObject << ", "
2606              << theVector   << ", "
2607              << theCopyGroups << ", '"
2608              << theMeshName << "' )";
2609     }
2610   }
2611   
2612   //dump "GetGroups"
2613   if(!myPreviewMode && mesh_i)
2614     mesh_i->GetGroups();
2615   
2616   return mesh._retn();
2617 }
2618
2619 //=======================================================================
2620 //function : rotate
2621 //purpose  : 
2622 //=======================================================================
2623
2624 SMESH::ListOfGroups*
2625 SMESH_MeshEditor_i::rotate(const SMESH::long_array & theIDsOfElements,
2626                            const SMESH::AxisStruct & theAxis,
2627                            CORBA::Double             theAngle,
2628                            CORBA::Boolean            theCopy,
2629                            const bool                theMakeGroups,
2630                            ::SMESH_Mesh*             theTargetMesh)
2631 {
2632   initData();
2633
2634   TIDSortedElemSet elements;
2635   arrayToSet(theIDsOfElements, GetMeshDS(), elements);
2636
2637   gp_Pnt P ( theAxis.x, theAxis.y, theAxis.z );
2638   gp_Vec V ( theAxis.vx, theAxis.vy, theAxis.vz );
2639
2640   gp_Trsf aTrsf;
2641   aTrsf.SetRotation( gp_Ax1( P, V ), theAngle);
2642
2643   ::SMESH_MeshEditor anEditor( myMesh );
2644   ::SMESH_MeshEditor::PGroupIDs groupIds =
2645       anEditor.Transform (elements, aTrsf, theCopy, theMakeGroups, theTargetMesh);
2646
2647   if(theCopy) {
2648     storeResult(anEditor);
2649   }
2650   return theMakeGroups ? getGroups(groupIds.get()) : 0;
2651 }
2652
2653 //=======================================================================
2654 //function : Rotate
2655 //purpose  :
2656 //=======================================================================
2657
2658 void SMESH_MeshEditor_i::Rotate(const SMESH::long_array & theIDsOfElements,
2659                                 const SMESH::AxisStruct & theAxis,
2660                                 CORBA::Double             theAngle,
2661                                 CORBA::Boolean            theCopy)
2662 {
2663   if ( !myPreviewMode ) {
2664     TPythonDump() << "axis = " << theAxis;
2665     TPythonDump() << this << ".Rotate( "
2666                   << theIDsOfElements
2667                   << ", axis, "
2668                   << theAngle << ", "
2669                   << theCopy << " )";
2670   }
2671   rotate(theIDsOfElements,
2672          theAxis,
2673          theAngle,
2674          theCopy,
2675          false);
2676 }
2677
2678 //=======================================================================
2679 //function : RotateObject
2680 //purpose  :
2681 //=======================================================================
2682
2683 void SMESH_MeshEditor_i::RotateObject(SMESH::SMESH_IDSource_ptr theObject,
2684                                       const SMESH::AxisStruct & theAxis,
2685                                       CORBA::Double             theAngle,
2686                                       CORBA::Boolean            theCopy)
2687 {
2688   if ( !myPreviewMode ) {
2689     TPythonDump() << "axis = " << theAxis;
2690     TPythonDump() << this << ".RotateObject( "
2691                   << theObject
2692                   << ", axis, "
2693                   << theAngle << ", "
2694                   << theCopy << " )";
2695   }
2696   SMESH::long_array_var anElementsId = theObject->GetIDs();
2697   rotate(anElementsId,
2698          theAxis,
2699          theAngle,
2700          theCopy,
2701          false);
2702 }
2703
2704 //=======================================================================
2705 //function : RotateMakeGroups
2706 //purpose  : 
2707 //=======================================================================
2708
2709 SMESH::ListOfGroups*
2710 SMESH_MeshEditor_i::RotateMakeGroups(const SMESH::long_array& theIDsOfElements,
2711                                      const SMESH::AxisStruct& theAxis,
2712                                      CORBA::Double            theAngle)
2713 {
2714   SMESH::ListOfGroups * aGroups =  rotate(theIDsOfElements,theAxis,theAngle,true,true);
2715   if ( !myPreviewMode ) {
2716     TPythonDump() << "axis = " << theAxis;
2717     TPythonDump aPythonDump;
2718     DumpGroupsList(aPythonDump,aGroups);
2719     aPythonDump << this << ".RotateMakeGroups( "
2720                 << theIDsOfElements
2721                 << ", axis, "
2722                 << theAngle << " )";
2723   }
2724   return aGroups;
2725 }
2726
2727 //=======================================================================
2728 //function : RotateObjectMakeGroups
2729 //purpose  : 
2730 //=======================================================================
2731
2732 SMESH::ListOfGroups*
2733 SMESH_MeshEditor_i::RotateObjectMakeGroups(SMESH::SMESH_IDSource_ptr theObject,
2734                                            const SMESH::AxisStruct&  theAxis,
2735                                            CORBA::Double             theAngle)
2736 {
2737   SMESH::long_array_var anElementsId = theObject->GetIDs();
2738   SMESH::ListOfGroups * aGroups =  rotate(anElementsId,theAxis,theAngle,true,true);
2739  
2740   if ( !myPreviewMode ) {
2741     TPythonDump() << "axis = " << theAxis;
2742     TPythonDump aPythonDump;
2743     DumpGroupsList(aPythonDump,aGroups);
2744     aPythonDump << this << ".RotateObjectMakeGroups( "
2745                   << theObject
2746                   << ", axis, "
2747                   << theAngle << " )";
2748   }
2749   return aGroups;
2750 }
2751
2752 //=======================================================================
2753 //function : RotateMakeMesh
2754 //purpose  : 
2755 //=======================================================================
2756
2757 SMESH::SMESH_Mesh_ptr 
2758 SMESH_MeshEditor_i::RotateMakeMesh(const SMESH::long_array& theIDsOfElements,
2759                                    const SMESH::AxisStruct& theAxis,
2760                                    CORBA::Double            theAngleInRadians,
2761                                    CORBA::Boolean           theCopyGroups,
2762                                    const char*              theMeshName)
2763 {
2764   SMESH::SMESH_Mesh_var mesh;
2765   SMESH_Mesh_i* mesh_i;
2766
2767   { // open new scope to dump "MakeMesh" command
2768     // and then "GetGroups" using SMESH_Mesh::GetGroups()
2769     
2770     TPythonDump pydump; // to prevent dump at mesh creation
2771
2772     mesh = makeMesh( theMeshName );
2773     mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2774     
2775     if ( mesh_i ) {
2776       rotate(theIDsOfElements, theAxis, theAngleInRadians,
2777              false, theCopyGroups, & mesh_i->GetImpl());
2778       mesh_i->CreateGroupServants();
2779     }
2780     if ( !myPreviewMode ) {
2781       pydump << mesh << " = " << this << ".RotateMakeMesh( "
2782              << theIDsOfElements << ", "
2783              << theAxis << ", "
2784              << theAngleInRadians   << ", "
2785              << theCopyGroups << ", '"
2786              << theMeshName << "' )";
2787     }
2788   }
2789   
2790   //dump "GetGroups"
2791   if(!myPreviewMode && mesh_i)
2792     mesh_i->GetGroups();
2793   
2794   return mesh._retn();
2795 }
2796
2797 //=======================================================================
2798 //function : RotateObjectMakeMesh
2799 //purpose  : 
2800 //=======================================================================
2801
2802 SMESH::SMESH_Mesh_ptr 
2803 SMESH_MeshEditor_i::RotateObjectMakeMesh(SMESH::SMESH_IDSource_ptr theObject,
2804                                          const SMESH::AxisStruct&  theAxis,
2805                                          CORBA::Double             theAngleInRadians,
2806                                          CORBA::Boolean            theCopyGroups,
2807                                          const char*               theMeshName)
2808 {
2809   SMESH::SMESH_Mesh_var mesh;
2810   SMESH_Mesh_i* mesh_i;
2811   
2812   {// open new scope to dump "MakeMesh" command
2813    // and then "GetGroups" using SMESH_Mesh::GetGroups()
2814     
2815     TPythonDump pydump; // to prevent dump at mesh creation
2816     mesh = makeMesh( theMeshName );
2817     mesh_i = SMESH::DownCast<SMESH_Mesh_i*>( mesh );
2818     
2819     if (mesh_i ) {
2820       SMESH::long_array_var anElementsId = theObject->GetIDs();
2821       rotate(anElementsId, theAxis, theAngleInRadians,
2822              false, theCopyGroups, & mesh_i->GetImpl());
2823       mesh_i->CreateGroupServants();
2824     }
2825     if ( !myPreviewMode ) {
2826       pydump << mesh << " = " << this << ".RotateObjectMakeMesh( "
2827              << theObject << ", "
2828              << theAxis << ", "
2829              << theAngleInRadians   << ", "
2830              << theCopyGroups << ", '"
2831              << theMeshName << "' )";
2832     }
2833   }
2834   
2835   //dump "GetGroups"
2836   if(!myPreviewMode && mesh_i)
2837     mesh_i->GetGroups();
2838   
2839   return mesh._retn();
2840 }
2841
2842 //=======================================================================
2843 //function : FindCoincidentNodes
2844 //purpose  :
2845 //=======================================================================
2846
2847 void SMESH_MeshEditor_i::FindCoincidentNodes (CORBA::Double                  Tolerance,
2848                                               SMESH::array_of_long_array_out GroupsOfNodes)
2849 {
2850   initData();
2851
2852   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2853   ::SMESH_MeshEditor anEditor( myMesh );
2854   set<const SMDS_MeshNode*> nodes; // no input nodes
2855   anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2856
2857   GroupsOfNodes = new SMESH::array_of_long_array;
2858   GroupsOfNodes->length( aListOfListOfNodes.size() );
2859   ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2860   for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2861     list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2862     list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2863     SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2864     aGroup.length( aListOfNodes.size() );
2865     for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2866       aGroup[ j ] = (*lIt)->GetID();
2867   }
2868   TPythonDump() << "coincident_nodes = " << this << ".FindCoincidentNodes( "
2869                 << Tolerance << " )";
2870 }
2871
2872 //=======================================================================
2873 //function : FindCoincidentNodesOnPart
2874 //purpose  :
2875 //=======================================================================
2876 void SMESH_MeshEditor_i::FindCoincidentNodesOnPart(SMESH::SMESH_IDSource_ptr      theObject,
2877                                                    CORBA::Double                  Tolerance,
2878                                                    SMESH::array_of_long_array_out GroupsOfNodes)
2879 {
2880   initData();
2881   SMESH::long_array_var aElementsId = theObject->GetIDs();
2882
2883   SMESHDS_Mesh* aMesh = GetMeshDS();
2884   set<const SMDS_MeshNode*> nodes;
2885
2886   if ( !CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2887       SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) {
2888     for(int i = 0; i < aElementsId->length(); i++) {
2889       CORBA::Long ind = aElementsId[i];
2890       const SMDS_MeshNode * elem = aMesh->FindNode(ind);
2891       if(elem)
2892         nodes.insert(elem);
2893     }
2894   }
2895   else {
2896     for(int i = 0; i < aElementsId->length(); i++) {
2897       CORBA::Long ind = aElementsId[i];
2898       const SMDS_MeshElement * elem = aMesh->FindElement(ind);
2899       if(elem) {
2900         SMDS_ElemIteratorPtr nIt = elem->nodesIterator();
2901         while ( nIt->more() )
2902           nodes.insert( nodes.end(),static_cast<const SMDS_MeshNode*>(nIt->next()));
2903       }
2904     }
2905   }
2906     
2907   
2908   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2909   ::SMESH_MeshEditor anEditor( myMesh );
2910   if(!nodes.empty())
2911     anEditor.FindCoincidentNodes( nodes, Tolerance, aListOfListOfNodes );
2912   
2913   GroupsOfNodes = new SMESH::array_of_long_array;
2914   GroupsOfNodes->length( aListOfListOfNodes.size() );
2915   ::SMESH_MeshEditor::TListOfListOfNodes::iterator llIt = aListOfListOfNodes.begin();
2916   for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) {
2917     list< const SMDS_MeshNode* >& aListOfNodes = *llIt;
2918     list< const SMDS_MeshNode* >::iterator lIt = aListOfNodes.begin();;
2919     SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ];
2920     aGroup.length( aListOfNodes.size() );
2921     for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ )
2922       aGroup[ j ] = (*lIt)->GetID();
2923   }
2924   TPythonDump() << "coincident_nodes_on_part = " << this << ".FindCoincidentNodesOnPart( "
2925                 <<theObject<<", "
2926                 << Tolerance << " )";
2927 }
2928
2929 //=======================================================================
2930 //function : MergeNodes
2931 //purpose  :
2932 //=======================================================================
2933
2934 void SMESH_MeshEditor_i::MergeNodes (const SMESH::array_of_long_array& GroupsOfNodes)
2935 {
2936   initData();
2937
2938   SMESHDS_Mesh* aMesh = GetMeshDS();
2939
2940   TPythonDump aTPythonDump;
2941   aTPythonDump << this << ".MergeNodes([";
2942   ::SMESH_MeshEditor::TListOfListOfNodes aListOfListOfNodes;
2943   for (int i = 0; i < GroupsOfNodes.length(); i++)
2944   {
2945     const SMESH::long_array& aNodeGroup = GroupsOfNodes[ i ];
2946     aListOfListOfNodes.push_back( list< const SMDS_MeshNode* >() );
2947     list< const SMDS_MeshNode* >& aListOfNodes = aListOfListOfNodes.back();
2948     for ( int j = 0; j < aNodeGroup.length(); j++ )
2949     {
2950       CORBA::Long index = aNodeGroup[ j ];
2951       const SMDS_MeshNode * node = aMesh->FindNode(index);
2952       if ( node )
2953         aListOfNodes.push_back( node );
2954     }
2955     if ( aListOfNodes.size() < 2 )
2956       aListOfListOfNodes.pop_back();
2957
2958     if ( i > 0 ) aTPythonDump << ", ";
2959     aTPythonDump << aNodeGroup;
2960   }
2961   ::SMESH_MeshEditor anEditor( myMesh );
2962   anEditor.MergeNodes( aListOfListOfNodes );
2963
2964   aTPythonDump <<  "])";
2965 }
2966
2967 //=======================================================================
2968 //function : FindEqualElements
2969 //purpose  :
2970 //=======================================================================
2971 void SMESH_MeshEditor_i::FindEqualElements(SMESH::SMESH_IDSource_ptr      theObject,
2972                                            SMESH::array_of_long_array_out GroupsOfElementsID)
2973 {
2974   initData();
2975   if ( !(!CORBA::is_nil(SMESH::SMESH_GroupBase::_narrow(theObject)) &&
2976          SMESH::SMESH_GroupBase::_narrow(theObject)->GetType() == SMESH::NODE) ) {
2977     typedef list<int> TListOfIDs;
2978     set<const SMDS_MeshElement*> elems;
2979     SMESH::long_array_var aElementsId = theObject->GetIDs();
2980     SMESHDS_Mesh* aMesh = GetMeshDS();
2981
2982     for(int i = 0; i < aElementsId->length(); i++) {
2983       CORBA::Long anID = aElementsId[i];
2984       const SMDS_MeshElement * elem = aMesh->FindElement(anID);
2985       if (elem) {
2986         elems.insert(elem);
2987       }
2988     }
2989
2990     ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
2991     ::SMESH_MeshEditor anEditor( myMesh );
2992     anEditor.FindEqualElements( elems, aListOfListOfElementsID );
2993
2994     GroupsOfElementsID = new SMESH::array_of_long_array;
2995     GroupsOfElementsID->length( aListOfListOfElementsID.size() );
2996
2997     ::SMESH_MeshEditor::TListOfListOfElementsID::iterator arraysIt = aListOfListOfElementsID.begin();
2998     for (CORBA::Long j = 0; arraysIt != aListOfListOfElementsID.end(); ++arraysIt, ++j) {
2999       SMESH::long_array& aGroup = (*GroupsOfElementsID)[ j ];
3000       TListOfIDs& listOfIDs = *arraysIt;
3001       aGroup.length( listOfIDs.size() );
3002       TListOfIDs::iterator idIt = listOfIDs.begin();
3003       for (int k = 0; idIt != listOfIDs.end(); ++idIt, ++k ) {
3004         aGroup[ k ] = *idIt;
3005       }
3006     }
3007
3008   TPythonDump() << "equal_elements = " << this << ".FindEqualElements( "
3009                 <<theObject<<" )";
3010   }
3011 }
3012
3013 //=======================================================================
3014 //function : MergeElements
3015 //purpose  :
3016 //=======================================================================
3017
3018 void SMESH_MeshEditor_i::MergeElements(const SMESH::array_of_long_array& GroupsOfElementsID)
3019 {
3020   initData();
3021
3022   TPythonDump aTPythonDump;
3023   aTPythonDump << this << ".MergeElements( [";
3024
3025   ::SMESH_MeshEditor::TListOfListOfElementsID aListOfListOfElementsID;
3026
3027   for (int i = 0; i < GroupsOfElementsID.length(); i++) {
3028     const SMESH::long_array& anElemsIDGroup = GroupsOfElementsID[ i ];
3029     aListOfListOfElementsID.push_back( list< int >() );
3030     list< int >& aListOfElemsID = aListOfListOfElementsID.back();
3031     for ( int j = 0; j < anElemsIDGroup.length(); j++ ) {
3032       CORBA::Long id = anElemsIDGroup[ j ];
3033       aListOfElemsID.push_back( id );
3034     }
3035     if ( aListOfElemsID.size() < 2 )
3036       aListOfListOfElementsID.pop_back();
3037     if ( i > 0 ) aTPythonDump << ", ";
3038     aTPythonDump << anElemsIDGroup;
3039   }
3040
3041   ::SMESH_MeshEditor anEditor( myMesh );
3042   anEditor.MergeElements(aListOfListOfElementsID);
3043
3044   aTPythonDump << "] )";
3045 }
3046
3047 //=======================================================================
3048 //function : MergeEqualElements
3049 //purpose  :
3050 //=======================================================================
3051
3052 void SMESH_MeshEditor_i::MergeEqualElements()
3053 {
3054   initData();
3055
3056   ::SMESH_MeshEditor anEditor( myMesh );
3057   anEditor.MergeEqualElements();
3058
3059   TPythonDump() << this << ".MergeEqualElements()";
3060 }
3061
3062 //================================================================================
3063 /*!
3064  * \brief If the given ID is a valid node ID (nodeID > 0), just move this node, else
3065  * move the node closest to the point to point's location and return ID of the node
3066  */
3067 //================================================================================
3068
3069 CORBA::Long SMESH_MeshEditor_i::MoveClosestNodeToPoint(CORBA::Double x,
3070                                                        CORBA::Double y,
3071                                                        CORBA::Double z,
3072                                                        CORBA::Long   theNodeID)
3073 {
3074   // We keep myNodeSearcher until any mesh modification:
3075   // 1) initData() deletes myNodeSearcher at any edition,
3076   // 2) TNodeSearcherDeleter - at any mesh compute event and mesh change
3077
3078   initData();
3079
3080   int nodeID = theNodeID;
3081   const SMDS_MeshNode* node = GetMeshDS()->FindNode( nodeID );
3082   if ( !node )
3083   {
3084     static TNodeSearcherDeleter deleter;
3085     deleter.Set( myMesh );
3086     if ( !myNodeSearcher ) {
3087       ::SMESH_MeshEditor anEditor( myMesh );
3088       myNodeSearcher = anEditor.GetNodeSearcher();
3089     }
3090     gp_Pnt p( x,y,z );
3091     node = myNodeSearcher->FindClosestTo( p );
3092   }
3093   if ( node ) {
3094     nodeID = node->GetID();
3095     if ( myPreviewMode ) // make preview data
3096     {
3097       // in a preview mesh, make edges linked to a node
3098       TPreviewMesh tmpMesh;
3099       TIDSortedElemSet linkedNodes;
3100       ::SMESH_MeshEditor::GetLinkedNodes( node, linkedNodes );
3101       TIDSortedElemSet::iterator nIt = linkedNodes.begin();
3102       for ( ; nIt != linkedNodes.end(); ++nIt )
3103       {
3104         SMDS_MeshEdge edge( node, cast2Node( *nIt ));
3105         tmpMesh.Copy( &edge );
3106       }
3107       // move copied node
3108       node = tmpMesh.GetMeshDS()->FindNode( nodeID );
3109       if ( node )
3110         tmpMesh.GetMeshDS()->MoveNode(node, x, y, z);
3111       // fill preview data
3112       ::SMESH_MeshEditor anEditor( & tmpMesh );
3113       storeResult( anEditor );
3114     }
3115     else
3116     {
3117       GetMeshDS()->MoveNode(node, x, y, z);
3118     }
3119   }
3120
3121   if ( !myPreviewMode ) {
3122     TPythonDump() << "nodeID = " << this
3123                   << ".MoveClosestNodeToPoint( "<< x << ", " << y << ", " << z
3124                   << ", " << nodeID << " )";
3125   }
3126
3127   return nodeID;
3128 }
3129
3130 //=======================================================================
3131 //function : convError
3132 //purpose  :
3133 //=======================================================================
3134
3135 #define RETCASE(enm) case ::SMESH_MeshEditor::enm: return SMESH::SMESH_MeshEditor::enm;
3136
3137 static SMESH::SMESH_MeshEditor::Sew_Error convError( const::SMESH_MeshEditor::Sew_Error e )
3138 {
3139   switch ( e ) {
3140   RETCASE( SEW_OK );
3141   RETCASE( SEW_BORDER1_NOT_FOUND );
3142   RETCASE( SEW_BORDER2_NOT_FOUND );
3143   RETCASE( SEW_BOTH_BORDERS_NOT_FOUND );
3144   RETCASE( SEW_BAD_SIDE_NODES );
3145   RETCASE( SEW_VOLUMES_TO_SPLIT );
3146   RETCASE( SEW_DIFF_NB_OF_ELEMENTS );
3147   RETCASE( SEW_TOPO_DIFF_SETS_OF_ELEMENTS );
3148   RETCASE( SEW_BAD_SIDE1_NODES );
3149   RETCASE( SEW_BAD_SIDE2_NODES );
3150   }
3151   return SMESH::SMESH_MeshEditor::SEW_OK;
3152 }
3153
3154 //=======================================================================
3155 //function : SewFreeBorders
3156 //purpose  :
3157 //=======================================================================
3158
3159 SMESH::SMESH_MeshEditor::Sew_Error
3160   SMESH_MeshEditor_i::SewFreeBorders(CORBA::Long FirstNodeID1,
3161                                      CORBA::Long SecondNodeID1,
3162                                      CORBA::Long LastNodeID1,
3163                                      CORBA::Long FirstNodeID2,
3164                                      CORBA::Long SecondNodeID2,
3165                                      CORBA::Long LastNodeID2,
3166                                      CORBA::Boolean CreatePolygons,
3167                                      CORBA::Boolean CreatePolyedrs)
3168 {
3169   initData();
3170
3171   SMESHDS_Mesh* aMesh = GetMeshDS();
3172
3173   const SMDS_MeshNode* aBorderFirstNode  = aMesh->FindNode( FirstNodeID1  );
3174   const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3175   const SMDS_MeshNode* aBorderLastNode   = aMesh->FindNode( LastNodeID1   );
3176   const SMDS_MeshNode* aSide2FirstNode   = aMesh->FindNode( FirstNodeID2  );
3177   const SMDS_MeshNode* aSide2SecondNode  = aMesh->FindNode( SecondNodeID2 );
3178   const SMDS_MeshNode* aSide2ThirdNode   = aMesh->FindNode( LastNodeID2   );
3179
3180   if (!aBorderFirstNode ||
3181       !aBorderSecondNode||
3182       !aBorderLastNode)
3183     return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3184   if (!aSide2FirstNode  ||
3185       !aSide2SecondNode ||
3186       !aSide2ThirdNode)
3187     return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3188
3189   TPythonDump() << "error = " << this << ".SewFreeBorders( "
3190                 << FirstNodeID1  << ", "
3191                 << SecondNodeID1 << ", "
3192                 << LastNodeID1   << ", "
3193                 << FirstNodeID2  << ", "
3194                 << SecondNodeID2 << ", "
3195                 << LastNodeID2   << ", "
3196                 << CreatePolygons<< ", "
3197                 << CreatePolyedrs<< " )";
3198
3199   ::SMESH_MeshEditor anEditor( myMesh );
3200   SMESH::SMESH_MeshEditor::Sew_Error error =
3201     convError( anEditor.SewFreeBorder (aBorderFirstNode,
3202                                        aBorderSecondNode,
3203                                        aBorderLastNode,
3204                                        aSide2FirstNode,
3205                                        aSide2SecondNode,
3206                                        aSide2ThirdNode,
3207                                        true,
3208                                        CreatePolygons,
3209                                        CreatePolyedrs) );
3210
3211   storeResult(anEditor);
3212
3213   return error;
3214 }
3215
3216
3217 //=======================================================================
3218 //function : SewConformFreeBorders
3219 //purpose  :
3220 //=======================================================================
3221
3222 SMESH::SMESH_MeshEditor::Sew_Error
3223 SMESH_MeshEditor_i::SewConformFreeBorders(CORBA::Long FirstNodeID1,
3224                                           CORBA::Long SecondNodeID1,
3225                                           CORBA::Long LastNodeID1,
3226                                           CORBA::Long FirstNodeID2,
3227                                           CORBA::Long SecondNodeID2)
3228 {
3229   initData();
3230
3231   SMESHDS_Mesh* aMesh = GetMeshDS();
3232
3233   const SMDS_MeshNode* aBorderFirstNode  = aMesh->FindNode( FirstNodeID1  );
3234   const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeID1 );
3235   const SMDS_MeshNode* aBorderLastNode   = aMesh->FindNode( LastNodeID1   );
3236   const SMDS_MeshNode* aSide2FirstNode   = aMesh->FindNode( FirstNodeID2  );
3237   const SMDS_MeshNode* aSide2SecondNode  = aMesh->FindNode( SecondNodeID2 );
3238   const SMDS_MeshNode* aSide2ThirdNode   = 0;
3239
3240   if (!aBorderFirstNode ||
3241       !aBorderSecondNode||
3242       !aBorderLastNode )
3243     return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3244   if (!aSide2FirstNode  ||
3245       !aSide2SecondNode)
3246     return SMESH::SMESH_MeshEditor::SEW_BORDER2_NOT_FOUND;
3247
3248   TPythonDump() << "error = " << this << ".SewConformFreeBorders( "
3249                 << FirstNodeID1  << ", "
3250                 << SecondNodeID1 << ", "
3251                 << LastNodeID1   << ", "
3252                 << FirstNodeID2  << ", "
3253                 << SecondNodeID2 << " )";
3254
3255   ::SMESH_MeshEditor anEditor( myMesh );
3256   SMESH::SMESH_MeshEditor::Sew_Error error =
3257     convError( anEditor.SewFreeBorder (aBorderFirstNode,
3258                                        aBorderSecondNode,
3259                                        aBorderLastNode,
3260                                        aSide2FirstNode,
3261                                        aSide2SecondNode,
3262                                        aSide2ThirdNode,
3263                                        true,
3264                                        false, false) );
3265
3266   storeResult(anEditor);
3267
3268   return error;
3269 }
3270
3271
3272 //=======================================================================
3273 //function : SewBorderToSide
3274 //purpose  :
3275 //=======================================================================
3276
3277 SMESH::SMESH_MeshEditor::Sew_Error
3278 SMESH_MeshEditor_i::SewBorderToSide(CORBA::Long FirstNodeIDOnFreeBorder,
3279                                     CORBA::Long SecondNodeIDOnFreeBorder,
3280                                     CORBA::Long LastNodeIDOnFreeBorder,
3281                                     CORBA::Long FirstNodeIDOnSide,
3282                                     CORBA::Long LastNodeIDOnSide,
3283                                     CORBA::Boolean CreatePolygons,
3284                                     CORBA::Boolean CreatePolyedrs)
3285 {
3286   initData();
3287
3288   SMESHDS_Mesh* aMesh = GetMeshDS();
3289
3290   const SMDS_MeshNode* aBorderFirstNode  = aMesh->FindNode( FirstNodeIDOnFreeBorder  );
3291   const SMDS_MeshNode* aBorderSecondNode = aMesh->FindNode( SecondNodeIDOnFreeBorder );
3292   const SMDS_MeshNode* aBorderLastNode   = aMesh->FindNode( LastNodeIDOnFreeBorder   );
3293   const SMDS_MeshNode* aSide2FirstNode   = aMesh->FindNode( FirstNodeIDOnSide  );
3294   const SMDS_MeshNode* aSide2SecondNode  = aMesh->FindNode( LastNodeIDOnSide );
3295   const SMDS_MeshNode* aSide2ThirdNode   = 0;
3296
3297   if (!aBorderFirstNode ||
3298       !aBorderSecondNode||
3299       !aBorderLastNode  )
3300     return SMESH::SMESH_MeshEditor::SEW_BORDER1_NOT_FOUND;
3301   if (!aSide2FirstNode  ||
3302       !aSide2SecondNode)
3303     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE_NODES;
3304
3305   TPythonDump() << "error = " << this << ".SewBorderToSide( "
3306                 << FirstNodeIDOnFreeBorder  << ", "
3307                 << SecondNodeIDOnFreeBorder << ", "
3308                 << LastNodeIDOnFreeBorder   << ", "
3309                 << FirstNodeIDOnSide        << ", "
3310                 << LastNodeIDOnSide         << ", "
3311                 << CreatePolygons           << ", "
3312                 << CreatePolyedrs           << ") ";
3313
3314   ::SMESH_MeshEditor anEditor( myMesh );
3315   SMESH::SMESH_MeshEditor::Sew_Error error =
3316     convError( anEditor.SewFreeBorder (aBorderFirstNode,
3317                                        aBorderSecondNode,
3318                                        aBorderLastNode,
3319                                        aSide2FirstNode,
3320                                        aSide2SecondNode,
3321                                        aSide2ThirdNode,
3322                                        false,
3323                                        CreatePolygons,
3324                                        CreatePolyedrs) );
3325
3326   storeResult(anEditor);
3327
3328   return error;
3329 }
3330
3331
3332 //=======================================================================
3333 //function : SewSideElements
3334 //purpose  :
3335 //=======================================================================
3336
3337 SMESH::SMESH_MeshEditor::Sew_Error
3338 SMESH_MeshEditor_i::SewSideElements(const SMESH::long_array& IDsOfSide1Elements,
3339                                     const SMESH::long_array& IDsOfSide2Elements,
3340                                     CORBA::Long NodeID1OfSide1ToMerge,
3341                                     CORBA::Long NodeID1OfSide2ToMerge,
3342                                     CORBA::Long NodeID2OfSide1ToMerge,
3343                                     CORBA::Long NodeID2OfSide2ToMerge)
3344 {
3345   initData();
3346
3347   SMESHDS_Mesh* aMesh = GetMeshDS();
3348
3349   const SMDS_MeshNode* aFirstNode1ToMerge  = aMesh->FindNode( NodeID1OfSide1ToMerge );
3350   const SMDS_MeshNode* aFirstNode2ToMerge  = aMesh->FindNode( NodeID1OfSide2ToMerge );
3351   const SMDS_MeshNode* aSecondNode1ToMerge = aMesh->FindNode( NodeID2OfSide1ToMerge );
3352   const SMDS_MeshNode* aSecondNode2ToMerge = aMesh->FindNode( NodeID2OfSide2ToMerge );
3353
3354   if (!aFirstNode1ToMerge ||
3355       !aFirstNode2ToMerge )
3356     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE1_NODES;
3357   if (!aSecondNode1ToMerge||
3358       !aSecondNode2ToMerge)
3359     return SMESH::SMESH_MeshEditor::SEW_BAD_SIDE2_NODES;
3360
3361   TIDSortedElemSet aSide1Elems, aSide2Elems;
3362   arrayToSet(IDsOfSide1Elements, aMesh, aSide1Elems);
3363   arrayToSet(IDsOfSide2Elements, aMesh, aSide2Elems);
3364
3365   TPythonDump() << "error = " << this << ".SewSideElements( "
3366                 << IDsOfSide1Elements << ", "
3367                 << IDsOfSide2Elements << ", "
3368                 << NodeID1OfSide1ToMerge << ", "
3369                 << NodeID1OfSide2ToMerge << ", "
3370                 << NodeID2OfSide1ToMerge << ", "
3371                 << NodeID2OfSide2ToMerge << ")";
3372
3373   ::SMESH_MeshEditor anEditor( myMesh );
3374   SMESH::SMESH_MeshEditor::Sew_Error error =
3375     convError( anEditor.SewSideElements (aSide1Elems, aSide2Elems,
3376                                          aFirstNode1ToMerge,
3377                                          aFirstNode2ToMerge,
3378                                          aSecondNode1ToMerge,
3379                                          aSecondNode2ToMerge));
3380
3381   storeResult(anEditor);
3382
3383   return error;
3384 }
3385
3386 //================================================================================
3387 /*!
3388  * \brief Set new nodes for given element
3389   * \param ide - element id
3390   * \param newIDs - new node ids
3391   * \retval CORBA::Boolean - true if result is OK
3392  */
3393 //================================================================================
3394
3395 CORBA::Boolean SMESH_MeshEditor_i::ChangeElemNodes(CORBA::Long ide,
3396                                                    const SMESH::long_array& newIDs)
3397 {
3398   initData();
3399
3400   const SMDS_MeshElement* elem = GetMeshDS()->FindElement(ide);
3401   if(!elem) return false;
3402
3403   int nbn = newIDs.length();
3404   int i=0;
3405   vector<const SMDS_MeshNode*> aNodes(nbn);
3406   int nbn1=-1;
3407   for(; i<nbn; i++) {
3408     const SMDS_MeshNode* aNode = GetMeshDS()->FindNode(newIDs[i]);
3409     if(aNode) {
3410       nbn1++;
3411       aNodes[nbn1] = aNode;
3412     }
3413   }
3414   TPythonDump() << "isDone = " << this << ".ChangeElemNodes( "
3415                 << ide << ", " << newIDs << " )";
3416 #ifdef _DEBUG_
3417   TPythonDump() << "print 'ChangeElemNodes: ', isDone";
3418 #endif
3419
3420   return GetMeshDS()->ChangeElementNodes( elem, & aNodes[0], nbn1+1 );
3421 }
3422   
3423 //================================================================================
3424 /*!
3425  * \brief Update myLastCreated* or myPreviewData
3426   * \param anEditor - it contains last modification results
3427  */
3428 //================================================================================
3429
3430 void SMESH_MeshEditor_i::storeResult(::SMESH_MeshEditor& anEditor)
3431 {
3432   if ( myPreviewMode ) { // --- MeshPreviewStruct filling --- 
3433
3434     list<int> aNodesConnectivity;
3435     typedef map<int, int> TNodesMap;
3436     TNodesMap nodesMap;
3437
3438     TPreviewMesh * aPreviewMesh = dynamic_cast< TPreviewMesh* >( anEditor.GetMesh() );
3439     SMDSAbs_ElementType previewType = aPreviewMesh->myPreviewType;
3440
3441     SMESHDS_Mesh* aMeshDS = anEditor.GetMeshDS();
3442     int nbEdges = aMeshDS->NbEdges();
3443     int nbFaces = aMeshDS->NbFaces();
3444     int nbVolum = aMeshDS->NbVolumes();
3445     switch ( previewType ) {
3446     case SMDSAbs_Edge  : nbFaces = nbVolum = 0; break;
3447     case SMDSAbs_Face  : nbEdges = nbVolum = 0; break;
3448     case SMDSAbs_Volume: nbEdges = nbFaces = 0; break;
3449     default:;
3450     }
3451     myPreviewData->nodesXYZ.length(aMeshDS->NbNodes());
3452     myPreviewData->elementTypes.length(nbEdges + nbFaces + nbVolum);
3453     int i = 0, j = 0;
3454     SMDS_ElemIteratorPtr itMeshElems = aMeshDS->elementsIterator();
3455
3456     while ( itMeshElems->more() ) {
3457       const SMDS_MeshElement* aMeshElem = itMeshElems->next();
3458       if ( previewType != SMDSAbs_All && aMeshElem->GetType() != previewType )
3459         continue;
3460
3461       SMDS_ElemIteratorPtr itElemNodes = aMeshElem->nodesIterator();
3462       while ( itElemNodes->more() ) {
3463         const SMDS_MeshNode* aMeshNode = 
3464           static_cast<const SMDS_MeshNode*>( itElemNodes->next() );
3465         int aNodeID = aMeshNode->GetID();
3466         TNodesMap::iterator anIter = nodesMap.find(aNodeID);
3467         if ( anIter == nodesMap.end() ) {
3468           // filling the nodes coordinates
3469           myPreviewData->nodesXYZ[j].x = aMeshNode->X();
3470           myPreviewData->nodesXYZ[j].y = aMeshNode->Y();
3471           myPreviewData->nodesXYZ[j].z = aMeshNode->Z();
3472           anIter = nodesMap.insert( make_pair(aNodeID, j) ).first;
3473           j++;
3474         }
3475         aNodesConnectivity.push_back(anIter->second);
3476       }
3477
3478       // filling the elements types
3479       SMDSAbs_ElementType aType;
3480       bool isPoly;
3481       /*if (aMeshElem->GetType() == SMDSAbs_Volume) {
3482         aType = SMDSAbs_Node;
3483         isPoly = false;
3484       }
3485       else*/ {
3486         aType = aMeshElem->GetType();
3487         isPoly = aMeshElem->IsPoly();
3488       }
3489
3490       myPreviewData->elementTypes[i].SMDS_ElementType = (SMESH::ElementType) aType;
3491       myPreviewData->elementTypes[i].isPoly = isPoly;
3492       myPreviewData->elementTypes[i].nbNodesInElement = aMeshElem->NbNodes();
3493       i++;
3494
3495     }
3496     myPreviewData->nodesXYZ.length( j );
3497
3498     // filling the elements connectivities
3499     list<int>::iterator aConnIter = aNodesConnectivity.begin();
3500     myPreviewData->elementConnectivities.length(aNodesConnectivity.size());
3501     for( int i = 0; aConnIter != aNodesConnectivity.end(); aConnIter++, i++ )
3502       myPreviewData->elementConnectivities[i] = *aConnIter;
3503     
3504     return;
3505   }
3506
3507   {
3508     // add new nodes into myLastCreatedNodes
3509     const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedNodes();
3510     myLastCreatedNodes->length(aSeq.Length());
3511     for(int i=0; i<aSeq.Length(); i++)
3512       myLastCreatedNodes[i] = aSeq.Value(i+1)->GetID();
3513   }
3514   {
3515     // add new elements into myLastCreatedElems
3516     const SMESH_SequenceOfElemPtr& aSeq = anEditor.GetLastCreatedElems();
3517     myLastCreatedElems->length(aSeq.Length());
3518     for(int i=0; i<aSeq.Length(); i++)
3519       myLastCreatedElems[i] = aSeq.Value(i+1)->GetID();
3520   }
3521 }
3522
3523 //================================================================================
3524 /*!
3525  * Return data of mesh edition preview
3526  */
3527 //================================================================================
3528
3529 SMESH::MeshPreviewStruct* SMESH_MeshEditor_i::GetPreviewData()
3530 {
3531   return myPreviewData._retn();
3532 }
3533
3534 //================================================================================
3535 /*!
3536  * \brief Returns list of it's IDs of created nodes
3537   * \retval SMESH::long_array* - list of node ID
3538  */
3539 //================================================================================
3540
3541 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedNodes()
3542 {
3543   return myLastCreatedNodes._retn();
3544 }
3545
3546 //================================================================================
3547 /*!
3548  * \brief Returns list of it's IDs of created elements
3549   * \retval SMESH::long_array* - list of elements' ID
3550  */
3551 //================================================================================
3552
3553 SMESH::long_array* SMESH_MeshEditor_i::GetLastCreatedElems()
3554 {
3555   return myLastCreatedElems._retn();
3556 }
3557
3558 //=======================================================================
3559 //function : ConvertToQuadratic
3560 //purpose  :
3561 //=======================================================================
3562
3563 void SMESH_MeshEditor_i::ConvertToQuadratic(CORBA::Boolean theForce3d)
3564 {
3565   ::SMESH_MeshEditor anEditor( myMesh );
3566   anEditor.ConvertToQuadratic(theForce3d);
3567   TPythonDump() << this << ".ConvertToQuadratic( " << theForce3d << " )";
3568 }
3569
3570 //=======================================================================
3571 //function : ConvertFromQuadratic
3572 //purpose  : 
3573 //=======================================================================
3574
3575 CORBA::Boolean SMESH_MeshEditor_i::ConvertFromQuadratic()
3576 {
3577   ::SMESH_MeshEditor anEditor( myMesh );
3578   CORBA::Boolean isDone = anEditor.ConvertFromQuadratic();
3579   TPythonDump() << this << ".ConvertFromQuadratic()";
3580   return isDone;
3581 }
3582
3583 //=======================================================================
3584 //function : makeMesh
3585 //purpose  : create a named imported mesh 
3586 //=======================================================================
3587
3588 SMESH::SMESH_Mesh_ptr SMESH_MeshEditor_i::makeMesh(const char* theMeshName)
3589 {
3590   SMESH_Gen_i* gen = SMESH_Gen_i::GetSMESHGen();
3591   SMESH::SMESH_Mesh_var mesh = gen->CreateEmptyMesh();
3592   SALOMEDS::Study_var study = gen->GetCurrentStudy();
3593   SALOMEDS::SObject_var meshSO = gen->ObjectToSObject( study, mesh );
3594   gen->SetName( meshSO, theMeshName, "Mesh" );
3595
3596   SALOMEDS::StudyBuilder_var builder = study->NewBuilder();
3597   SALOMEDS::GenericAttribute_var anAttr
3598     = builder->FindOrCreateAttribute( meshSO, "AttributePixMap" );
3599   SALOMEDS::AttributePixMap::_narrow( anAttr )->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3600
3601   return mesh._retn();
3602 }
3603
3604 //=======================================================================
3605 //function : DumpGroupsList
3606 //purpose  : 
3607 //=======================================================================
3608 void SMESH_MeshEditor_i::DumpGroupsList(TPythonDump & theDumpPython, 
3609                                         const SMESH::ListOfGroups * theGroupList)
3610 {
3611   bool isDumpGroupList = theGroupList && theGroupList->length() > 0;
3612   if(isDumpGroupList) {
3613     theDumpPython << theGroupList << " = ";
3614   }
3615 }