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