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