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