Salome HOME
Fix for the "0052220: TC7.3.0:Unknown version of HexaBlock" issue.
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentModel.cxx
1 // Copyright (C) 2009-2013  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 //CS_TODO: relever les fonctions qui nécessitent updateData().
21 //        addGroupElement à tester
22 #include <algorithm>
23 #include <string>
24
25 #include "utilities.h"
26
27 #include "HEXABLOCKGUI_DocumentModel.hxx"
28 #include "HEXABLOCKGUI_DocumentItem.hxx"
29
30 #include "HEXABLOCKGUI.hxx"
31 #include "HEXABLOCKGUI_Trace.hxx"
32
33 #include "HexVertex.hxx"
34 #include "HexShape.hxx"
35 #include "HexSubShape.hxx"
36 #include "HexAssoEdge.hxx"
37 #include "HexBiCylinder.hxx"
38
39 #include <TopoDS.hxx>
40 #include <BRepBuilderAPI_MakeVertex.hxx>
41
42 #include "HEXABLOCKGUI_SalomeTools.hxx"
43
44 #include <SALOME_ListIO.hxx>
45 #include <SALOMEconfig.h>
46 #include <SUIT_ViewWindow.h>
47
48 #include <qglobal.h>
49
50 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
51
52 #include <Geom_Circle.hxx>
53 #include <gp_Circ.hxx>
54 #include <BRep_Tool.hxx>
55 #include <TopoDS_Edge.hxx>
56 //#define _DEVDEBUG_
57
58
59 using namespace std;
60 //using namespace HEXA_NS;
61 using namespace HEXABLOCK::GUI;
62
63 /*****************************************************************
64                       DocumentModel
65  *****************************************************************/
66 // DocumentModel::DocumentModel(QObject * parent):
67 DocumentModel::DocumentModel(HEXA_NS::Document* docIn, const QString& entryIn, QObject * parent):
68                               QStandardItemModel(parent),
69                               _hexaFile( new QTemporaryFile() ),
70                               _hexaDocument( docIn ),
71                               _entry( entryIn ),
72                               //   _hexaDocument(  new HEXA_NS::Document("/tmp/doc.hex") ), //CS_TODO
73
74                               _vertexDirItem( new QStandardItem(tr("TREE_ITEM_VERTEX")) ),
75                               _edgeDirItem( new QStandardItem(tr("TREE_ITEM_EDGE")) ),
76                               _quadDirItem( new QStandardItem(tr("TREE_ITEM_QUAD")) ),
77                               _hexaDirItem( new QStandardItem(tr("TREE_ITEM_HEXA")) ),
78
79                               _vectorDirItem( new QStandardItem(tr("TREE_ITEM_VECTOR")) ),
80                               _elementsDirItem( new QStandardItem(tr("TREE_ITEM_ELEMENT")) ),
81                               _crossElementsDirItem( new QStandardItem(tr("TREE_ITEM_CROSSELEMENT")) ),
82
83                               _explicitShapesDirItem( new QStandardItem(tr("TREE_ITEM_EXPSHAPE")) ),
84                               _implicitShapesDirItem( new QStandardItem(tr("TREE_ITEM_IMPSHAPE")) ),
85                               _cloudOfPointsDirItem( new QStandardItem(tr("TREE_ITEM_CLOUD_OF_POINT")) ),
86
87                               _groupDirItem( new QStandardItem(tr("TREE_ITEM_GROUP")) ),
88
89                               _lawDirItem( new QStandardItem(tr("TREE_ITEM_LAW")) ),
90                               _propagationDirItem( new QStandardItem(tr("TREE_ITEM_PROPAGATION")) ),
91
92                               _vertexItemFlags( Qt::NoItemFlags ),
93                               _edgeItemFlags( Qt::NoItemFlags ),
94                               _quadItemFlags( Qt::NoItemFlags ),
95                               _hexaItemFlags( Qt::NoItemFlags ),
96                               _vectorItemFlags( Qt::NoItemFlags ),
97                               _elementsItemFlags( Qt::NoItemFlags ),
98                               _crossElementsItemFlags( Qt::NoItemFlags ),
99
100                               _disallowEdition( false )
101 {
102     //   setColumnCount( 4 ); //CS_TEST
103     if ( !_hexaDocument && _hexaFile->open() ){
104         _hexaDocument =  new HEXA_NS::Document( _hexaFile->fileName().toLatin1() );
105         _hexaDocument->reorderFaces();
106     }
107
108     QStandardItem *parentItem = invisibleRootItem();
109     //   parentItem->setData( QString::number( reinterpret_cast<intptr_t>(_hexaDocument) ), HEXA_ENTRY_ROLE );
110     parentItem->setData( _entry, HEXA_ENTRY_ROLE );
111
112     _vertexDirItem->setData( VERTEX_DIR_TREE,           HEXA_TREE_ROLE );
113     _edgeDirItem->setData( EDGE_DIR_TREE,               HEXA_TREE_ROLE );
114     _quadDirItem->setData( QUAD_DIR_TREE,               HEXA_TREE_ROLE );
115     _hexaDirItem->setData( HEXA_DIR_TREE,               HEXA_TREE_ROLE );
116
117     _vectorDirItem->setData( VECTOR_DIR_TREE,           HEXA_TREE_ROLE );
118     _elementsDirItem->setData( ELEMENTS_DIR_TREE,           HEXA_TREE_ROLE );
119     _crossElementsDirItem->setData( CROSSELEMENTS_DIR_TREE, HEXA_TREE_ROLE );
120
121     _explicitShapesDirItem->setData( EXPLICIT_SHAPES_DIR_TREE, HEXA_TREE_ROLE );
122     _implicitShapesDirItem->setData( IMPLICIT_SHAPES_DIR_TREE, HEXA_TREE_ROLE );
123     _cloudOfPointsDirItem->setData( CLOUD_OF_POINTS_DIR_TREE, HEXA_TREE_ROLE );
124
125     _groupDirItem->setData( GROUP_DIR_TREE, HEXA_TREE_ROLE );
126
127     //CS_TODO associations
128
129     _lawDirItem->setData( LAW_DIR_TREE, HEXA_TREE_ROLE );
130     _propagationDirItem->setData( PROPAGATION_DIR_TREE, HEXA_TREE_ROLE );
131
132     parentItem->appendRow(_vertexDirItem);
133     parentItem->appendRow(_edgeDirItem);
134     parentItem->appendRow(_quadDirItem);
135     parentItem->appendRow(_hexaDirItem);
136
137     parentItem->appendRow(_vectorDirItem);
138     parentItem->appendRow(_elementsDirItem);
139     parentItem->appendRow(_crossElementsDirItem);
140
141     parentItem->appendRow(_explicitShapesDirItem);
142     parentItem->appendRow(_implicitShapesDirItem);
143
144     parentItem->appendRow(_groupDirItem);
145     parentItem->appendRow(_lawDirItem);
146     parentItem->appendRow(_propagationDirItem);
147 }
148
149 DocumentModel::~DocumentModel()
150 {
151     if (_hexaDocument != NULL)
152         delete _hexaDocument;
153
154     if (_hexaFile != NULL)
155         delete _hexaFile;
156 }
157
158 void DocumentModel::setName(const QString& name)
159 {
160     _hexaDocument->setName( name.toLocal8Bit().constData() );
161     emit nameChanged(QString(_hexaDocument->getName()));
162 }
163
164 HEXA_NS::EltBase* DocumentModel::getHexaPtr(const QModelIndex& iElt)
165 {
166     HEXA_NS::EltBase *elt = NULL;
167     switch ( /*data(iElt, HEXA_TREE_ROLE).toInt()*/iElt.data(HEXA_TREE_ROLE).toInt() ){
168     case VERTEX_TREE : elt = getHexaPtr<HEXA_NS::Vertex*>(iElt); break;
169     case EDGE_TREE : elt = getHexaPtr<HEXA_NS::Edge*>(iElt); break;
170     case QUAD_TREE : elt = getHexaPtr<HEXA_NS::Quad*>(iElt); break;
171     case HEXA_TREE : elt = getHexaPtr<HEXA_NS::Hexa*>(iElt); break;
172     case VECTOR_TREE : elt = getHexaPtr<HEXA_NS::Vector*>(iElt); break;
173     case ELEMENTS_TREE : elt = getHexaPtr<HEXA_NS::Elements*>(iElt); break;
174 //  case CROSSELEMENTS_TREE : elt = getHexaPtr<HEXA_NS::CrossElements*>(iElt); break;
175     case GEOMSHAPE_TREE: elt = getHexaPtr<HEXA_NS::NewShape*>(iElt); break;
176     case GEOMPOINT_TREE: elt = getHexaPtr<HEXA_NS::VertexShape*>(iElt); break;
177     case GEOMEDGE_TREE:  elt = getHexaPtr<HEXA_NS::EdgeShape*>(iElt); break;
178     case GEOMFACE_TREE:  elt = getHexaPtr<HEXA_NS::FaceShape*>(iElt); break;
179     }
180     return elt;
181 }
182
183 //get the number of elements of type 'eltType' in the document
184 int DocumentModel::getNbrElt(HEXA_NS::EnumElt eltType)
185 {
186     if (_hexaDocument == NULL) return 0;
187
188    return _hexaDocument->getNbrElt(eltType);
189 }
190
191 //get the number of elements of type 'eltType' used in the document
192 int DocumentModel::getNbrUsedElt(HEXA_NS::EnumElt eltType)
193 {
194     if (_hexaDocument == NULL) return 0;
195
196     switch(eltType) {
197     case HEXA_NS::EL_VERTEX:
198         return _hexaDocument->countUsedVertex();
199     case HEXA_NS::EL_EDGE:
200         return _hexaDocument->countUsedEdge();
201     case HEXA_NS::EL_QUAD:
202         return _hexaDocument->countUsedQuad();
203     case HEXA_NS::EL_HEXA:
204         return _hexaDocument->countUsedHexa();
205     default: return 0;
206     }
207 }
208
209 //associate a shape to the current document
210 bool DocumentModel::addShape(TopoDS_Shape& aShape, QString& name, bool publish)
211 {
212     if (aShape.IsNull() || name.isEmpty())
213         return false;
214     bool ok = (_hexaDocument != NULL ? _hexaDocument->addShape(aShape, name.toStdString().c_str()) != NULL : false);
215
216     // * publish the shape in the study
217     if (ok && publish)
218     {
219         HEXABLOCKGUI* module = HEXABLOCKGUI::getInstance();
220         if (module != NULL)
221         {
222             QMap<QString, TopoDS_Shape> topo_shapes;
223             topo_shapes[name] = aShape;
224             module->addInStudy(topo_shapes, docShapesEntry, docShapesName);
225         }
226     }
227
228     // * update data
229     if (ok)
230         updateGeomTree();
231
232     return ok;
233 }
234
235 //get the number of unused elements of type 'eltType' in the document
236 int DocumentModel::getNbrUnusedElt(HEXA_NS::EnumElt eltType)
237 {
238     if (_hexaDocument == NULL)
239         return 0;
240
241     return getNbrElt(eltType) - getNbrUsedElt(eltType);
242 }
243
244 // compute the length of the given edge
245 double DocumentModel::getLength(const QModelIndex& iEdge)
246 {
247     // * Get the pointer to the edge
248     HEXA_NS::Edge*        edge     = getHexaPtr<HEXA_NS::Edge*>(iEdge);
249     HEXA_NS::EdgeShape*   geomEdge = getHexaPtr<HEXA_NS::EdgeShape*>(iEdge);
250
251     // * The edge can be from VTK or OCC View
252     if (edge != NULL)
253         return edge->getLength();
254     else if (geomEdge != NULL)
255         return geomEdge->getLength();
256     else
257         return 0.;
258 }
259
260 // Compute the radius of the given edge
261 double DocumentModel::getRadius(const QModelIndex& iEdge)
262 {
263     // * Get the pointer to the edge
264     // * In our case only an OCC edge can have a radius
265     HEXA_NS::EdgeShape* edge = getHexaPtr<HEXA_NS::EdgeShape*>(iEdge);
266     if (edge == NULL)
267         return 0.;
268
269     return edge->getRadius();
270 }
271
272 // Compute the angle of the given edge (internal angle)
273 double DocumentModel::getAngle(const QModelIndex& iEdge)
274 {
275     // * Get the pointer to the edge
276     HEXA_NS::EdgeShape* edge = getHexaPtr<HEXA_NS::EdgeShape*>(iEdge);
277     if (edge == NULL)
278         return 0.;
279
280     return edge->getAngle();
281 }
282
283 //Load the current Document
284 void DocumentModel::load()
285 {
286     if (_hexaDocument == NULL)
287         return;
288
289     load(_hexaDocument->getName());
290 }
291
292
293 void DocumentModel::load( const QString& xmlFileName ) // Fill Data
294 {
295     _hexaDocument->loadXml(xmlFileName.toLocal8Bit().constData() );
296     clearAll();
297
298     fillData();
299 //    fillBuilder();
300     fillGeometry();
301     fillAssociation();
302     fillGroups();
303     fillMesh();
304
305     emit patternDataChanged();
306 }
307
308 bool DocumentModel::isEmpty() const
309 {
310     if (_hexaDocument == NULL) return true;
311     return _hexaDocument->isEmpty();
312 }
313
314 void DocumentModel::save( const QString& xmlFileName )
315 {
316     _hexaDocument->save( xmlFileName.toLocal8Bit().constData() );
317 }
318
319 QString DocumentModel::getName()
320 {
321     return _hexaDocument->getName();
322 }
323
324 void DocumentModel::updateData()
325 {
326     clearData();
327     fillData();
328     clearMesh();
329     fillMesh();
330     emit patternDataChanged();
331 }
332
333 void DocumentModel::updateGeomTree()
334 {
335     clearGeometry();
336     fillGeometry();
337 }
338
339 QModelIndex DocumentModel::addElementsToTree(HEXA_NS::Elements* helts, QStandardItem* tree)
340 {
341     QModelIndex eltIndex;
342     if (helts == NULL || tree == NULL)
343         return eltIndex;
344
345     updateData();
346     ElementsItem* eltsItem = new ElementsItem(helts);
347     tree->appendRow(eltsItem);
348
349     return eltsItem->index();
350 }
351
352 void DocumentModel::refresh()
353 {
354     clearAll();
355
356     fillData();
357 //    fillBuilder();
358     fillGeometry();
359     fillAssociation();
360     fillGroups();
361     fillMesh();
362
363     emit patternDataChanged();
364 }
365
366 void DocumentModel::clearAll()
367 {
368     clearData();
369 //    clearBuilder();
370     clearGeometry();
371     clearAssociation();
372     clearGroups();
373     clearMesh();
374 }
375
376 void DocumentModel::clearData()
377 {
378     _vertexDirItem->removeRows( 0, _vertexDirItem->rowCount() );
379     _edgeDirItem->removeRows(0, _edgeDirItem->rowCount() );
380     _quadDirItem->removeRows(0, _quadDirItem->rowCount() );
381     _hexaDirItem->removeRows(0, _hexaDirItem->rowCount() );
382
383     _vectorDirItem->removeRows(0, _vectorDirItem->rowCount() );
384     _elementsDirItem->removeRows(0, _elementsDirItem->rowCount() );
385     _crossElementsDirItem->removeRows(0, _crossElementsDirItem->rowCount() );
386 }
387
388
389 //void DocumentModel::clearBuilder()
390 //{
391 //    _vectorDirItem->removeRows(0, _vectorDirItem->rowCount() );
392 //    _elementsDirItem->removeRows(0, _elementsDirItem->rowCount() );
393 //    _crossElementsDirItem->removeRows(0, _crossElementsDirItem->rowCount() );
394 //}
395
396 void DocumentModel::clearGeometry()
397 {
398     _explicitShapesDirItem->removeRows(0, _explicitShapesDirItem->rowCount() );
399     _implicitShapesDirItem->removeRows(0, _implicitShapesDirItem->rowCount() );
400     _cloudOfPointsDirItem->removeRows(0, _cloudOfPointsDirItem->rowCount() );
401 }
402
403 void DocumentModel::clearAssociation()
404 {
405     //CS_TODO
406 }
407
408 void DocumentModel::clearGroups()
409 {
410     _groupDirItem->removeRows(0, _groupDirItem->rowCount() );
411 }
412
413 void DocumentModel::clearMesh()
414 {
415     _lawDirItem->removeRows(0, _lawDirItem->rowCount() );
416     _propagationDirItem->removeRows(0, _propagationDirItem->rowCount() );
417 }
418
419
420 void DocumentModel::fillData()
421 {
422     PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
423     if (pdsm == NULL)
424         return;
425     pdsm->clearHighlightedItems();
426
427     // DATA
428     HEXA_NS::Vertex *v     = NULL;
429     VertexItem      *vItem = NULL;
430     int nbVertex = _hexaDocument->countVertex();
431     for ( int i=0; i<nbVertex; ++i ){
432         v = _hexaDocument->getVertex(i);
433         vItem = new VertexItem(v, _entry);
434         _vertexDirItem->appendRow(vItem);
435     }
436
437     HEXA_NS::Edge *e     = NULL;
438     EdgeItem      *eItem = NULL;
439     int nbEdge = _hexaDocument->countEdge();
440     for ( int i=0; i<nbEdge; ++i ){
441         e = _hexaDocument->getEdge(i);
442         eItem = new EdgeItem(e, _entry);
443         _edgeDirItem->appendRow(eItem);
444     }
445
446     HEXA_NS::Quad *q     = NULL;
447     QuadItem      *qItem = NULL;
448     int nbQuad = _hexaDocument->countQuad();
449     for ( int i=0; i<nbQuad; ++i ){
450         q = _hexaDocument->getQuad(i);
451         qItem = new QuadItem(q, _entry);
452         _quadDirItem->appendRow(qItem);
453     }
454
455     HEXA_NS::Hexa *h     = NULL;
456     HexaItem      *hItem = NULL;
457     int nbHexa = _hexaDocument->countHexa();
458     for ( int i=0; i<nbHexa; ++i ){
459         h = _hexaDocument->getHexa(i);
460         hItem = new HexaItem(h, _entry);
461         _hexaDirItem->appendRow(hItem);
462     }
463
464     // +++++ Builder ++++++++++++++++++++++++++++++
465
466     HEXA_NS::Vector *vec     = NULL;
467     VectorItem      *vecItem = NULL;
468     int nbVector = _hexaDocument->countVector();
469     for ( int i=0; i<nbVector; ++i ){
470         vec = _hexaDocument->getVector(i);
471         vecItem = new VectorItem(vec);
472         _vectorDirItem->appendRow(vecItem);
473     }
474
475     //******* A VOIR AVEC ALAIN POUR LE REMPLISSAGE DE L'ARBRE ELEMENTS ET CROSSELEMENTS (ByCylinder) *******/
476     //******* OU SONT STOCKES LES ELEMENTS ET LES CROSSELEMENTS DANS LE DOCUMENT?                     ******/
477
478     //   _cylinderDirItem
479     //    HEXA_NS::Cylinder *c     = NULL;
480     //    HEXA_NS::Elements* c = NULL;
481     //    CylinderItem      *cItem = NULL;
482     //    ElementsItem* cItem = NULL;
483     //    int nbCylinder = _hexaDocument->countCylinder();
484     //    for ( int i=0; i<nbCylinder; ++i ){
485     //        c = _hexaDocument->getCylinder(i);
486     //        cItem = new CylinderItem(c, _entry);
487     //        cItem = new ElementsItem(c, _entry);
488     //        _cylinderDirItem->appendRow(cItem);
489     //        _elementsDirItem->appendRow(cItem);
490     //    }
491
492     //   _pipeDirItem
493     //    HEXA_NS::Pipe *p     = NULL;
494     //    HEXA_NS::Elements* p = NULL;
495     //    PipeItem      *pItem = NULL;
496     //    ElementsItem* pItem = NULL;
497     //    int nbPipe = _hexaDocument->countPipe();
498     //    for ( int i=0; i<nbPipe; ++i ){
499     //        p = _hexaDocument->getPipe(i);
500     //        pItem = new PipeItem(p);
501     //        pItem = new ElementsItem(p, _entry);
502     //        _pipeDirItem->appendRow(pItem);
503     //        _elementsDirItem->appendRow(pItem);
504     //    }
505     //********************************************************************************************************
506 }
507
508
509 //void DocumentModel::fillBuilder()
510 //{
511 //    HEXA_NS::Vector *v     = NULL;
512 //    VectorItem      *vItem = NULL;
513 //    int nbVector = _hexaDocument->countVector();
514 //    for ( int i=0; i<nbVector; ++i ){
515 //        v = _hexaDocument->getVector(i);
516 //        vItem = new VectorItem(v);
517 //        _vectorDirItem->appendRow(vItem);
518 //    }
519 //
520 //    //******* A VOIR AVEC ALAIN POUR LE REMPLISSAGE DE L'ARBRE ELEMENTS ET CROSSELEMENTS (ByCylinder) *******/
521 //    //******* OU SONT STOCKES LES ELEMENTS ET LES CROSSELEMENTS DANS LE DOCUMENT?                     ******/
522 //
523 //    //   _cylinderDirItem
524 ////    HEXA_NS::Cylinder *c     = NULL;
525 ////    HEXA_NS::Elements* c = NULL;
526 ////    CylinderItem      *cItem = NULL;
527 ////    ElementsItem* cItem = NULL;
528 ////    int nbCylinder = _hexaDocument->countCylinder();
529 ////    for ( int i=0; i<nbCylinder; ++i ){
530 ////        c = _hexaDocument->getCylinder(i);
531 ////        cItem = new CylinderItem(c, _entry);
532 ////        cItem = new ElementsItem(c, _entry);
533 ////        _cylinderDirItem->appendRow(cItem);
534 ////        _elementsDirItem->appendRow(cItem);
535 ////    }
536 //
537 //    //   _pipeDirItem
538 ////    HEXA_NS::Pipe *p     = NULL;
539 ////    HEXA_NS::Elements* p = NULL;
540 ////    PipeItem      *pItem = NULL;
541 ////    ElementsItem* pItem = NULL;
542 ////    int nbPipe = _hexaDocument->countPipe();
543 ////    for ( int i=0; i<nbPipe; ++i ){
544 ////        p = _hexaDocument->getPipe(i);
545 ////        pItem = new PipeItem(p);
546 ////        pItem = new ElementsItem(p, _entry);
547 ////        _pipeDirItem->appendRow(pItem);
548 ////        _elementsDirItem->appendRow(pItem);
549 ////    }
550 //    //********************************************************************************************************
551 //}
552
553 void DocumentModel::fillGeometry()
554 {
555     PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
556     if (_hexaDocument == NULL /*|| isEmpty()*/ || pgsm == NULL)
557         return;
558
559     HEXA_NS::NewShape* shape;
560     HEXA_NS::VertexShape* node;
561     HEXA_NS::EdgeShape* line;
562     HEXA_NS::FaceShape* face;
563     TopoDS_Compound vertexCompound;
564     BRep_Builder compoundBuilder;
565
566     // * fill the shape tree
567
568     shapeById.clear();
569     pgsm->clearHighlightedItems();
570     QMap<QString, TopoDS_Shape> topo_shapes;
571     int nbShapes = _hexaDocument->countShape();
572     for (int i=0; i < nbShapes; ++i)
573     {
574         shape = _hexaDocument->getShape(i);
575         QString shapeName = shape->getName();
576         if (!docShapesEntry.contains(shapeName))
577         {
578             if (shape->getOrigin() == HEXA_NS::SH_CLOUD)
579             {
580                 compoundBuilder.MakeCompound(vertexCompound);
581                 topo_shapes[shapeName] = vertexCompound;
582             }
583             else
584                 topo_shapes[shapeName] = shape->getShape();
585         }
586
587         GeomShapeItem* shItem = new GeomShapeItem(shape);
588         if (shape->getOrigin() == HEXA_NS::SH_IMPORT)
589             // * explicit shapes
590             _explicitShapesDirItem->appendRow(shItem);
591         else
592             // * implicit shapes
593             _implicitShapesDirItem->appendRow(shItem);
594
595         //add vertices to the tree
596         QStandardItem* geomPointDirItem = NULL;
597         if (shape->getOrigin() != HEXA_NS::SH_CLOUD)
598         {
599             geomPointDirItem = new QStandardItem(tr("TREE_ITEM_VERTEX"));
600             geomPointDirItem->setData( GEOMPOINT_DIR_TREE, HEXA_TREE_ROLE );
601         }
602         if (geomPointDirItem != NULL)
603             shItem->appendRow(geomPointDirItem);
604         int nbVertexShape = shape->countVertex();
605         for (int j=0; j < nbVertexShape; ++j)
606         {
607             node = shape->getVertexShape(j);
608             GeomPointItem* gPointItem = new GeomPointItem(node);
609             if (geomPointDirItem != NULL)
610                 geomPointDirItem->appendRow(gPointItem);
611             else
612                 shItem->appendRow(gPointItem);
613             shapeById[shapeName+","+QString::number(node->getIdent())] = node;
614
615             // * update the compound of vertices
616             if (shape->getOrigin() == HEXA_NS::SH_CLOUD && !vertexCompound.IsNull())
617                 compoundBuilder.Add(topo_shapes[shapeName], node->getShape());
618         }
619
620         if (shape->getOrigin() == HEXA_NS::SH_CLOUD)
621             continue; // * it's a cloud of points, there's no edges and no quads to fill
622
623         //add edges to the tree
624         QStandardItem* geomEdgeDirItem = new QStandardItem(tr("TREE_ITEM_EDGE"));
625         geomEdgeDirItem->setData( GEOMEDGE_DIR_TREE, HEXA_TREE_ROLE );
626         shItem->appendRow(geomEdgeDirItem);
627         int nbEdgeShape = shape->countEdge();
628         for (int j = 0; j < nbEdgeShape; ++j)
629         {
630             line = shape->getEdgeShape(j);
631             GeomEdgeItem* gEdgeItem = new GeomEdgeItem(line);
632             geomEdgeDirItem->appendRow(gEdgeItem);
633             shapeById[shapeName+","+QString::number(line->getIdent())] = line;
634         }
635
636         //add faces to the tree
637         QStandardItem* geomFaceDirItem = new QStandardItem(tr("TREE_ITEM_QUAD"));
638         geomFaceDirItem->setData( GEOMFACE_DIR_TREE, HEXA_TREE_ROLE );
639         shItem->appendRow(geomFaceDirItem);
640         int nbFaceShape = shape->countFace();
641         for (int j = 0; j < nbFaceShape; ++j)
642         {
643             face = shape->getFaceShape(j);
644             GeomFaceItem* gFaceItem = new GeomFaceItem(face);
645             geomFaceDirItem->appendRow(gFaceItem);
646             shapeById[shapeName+","+QString::number(face->getIdent())] = face;
647         }
648     }
649
650     if (topo_shapes.size() == 0)
651         return;
652
653     // * register shapes
654     HEXABLOCKGUI* module = HEXABLOCKGUI::getInstance();
655     if (module != NULL)
656         module->addInStudy(topo_shapes, docShapesEntry, docShapesName);
657 }
658
659 void DocumentModel::fillAssociation()
660 {
661 }
662
663 //------------------------------------------- NEW ITEMS
664 //void DocumentModel::fillGroups()
665 //{
666 //  HEXA_NS::Group *g     = NULL;
667 //  GroupItem      *gItem = NULL;
668 //  int nbGroup = _hexaDocument->countGroup();
669 //  for ( int i=0; i<nbGroup; ++i ){
670 //    g = _hexaDocument->getGroup(i);
671 //    gItem = new GroupItem(g, _entry);
672 //    _groupDirItem->appendRow(gItem);
673 //  }
674 //}
675 //
676 //void DocumentModel::fillMesh()
677 //{
678 //  HEXA_NS::Law *l     = NULL;
679 //  LawItem      *lItem = NULL;
680 //  int nbLaw = _hexaDocument->countLaw();
681 //  for ( int i=0; i<nbLaw; ++i ){
682 //    l = _hexaDocument->getLaw(i);
683 //    lItem = new LawItem(l);
684 //    _lawDirItem->appendRow(lItem);
685 //  }
686 //
687 //  HEXA_NS::Propagation *p     = NULL;
688 //  PropagationItem      *pItem = NULL;
689 //  int nbPropagation = _hexaDocument->countPropagation();
690 //  for ( int i=0; i<nbPropagation; ++i ){
691 //    p = _hexaDocument->getPropagation(i);
692 //    pItem = new PropagationItem(p, _entry);
693 //    pItem->setText(QString("Propagation%1").arg(i) );
694 //    _propagationDirItem->appendRow(pItem);
695 //  }
696 //}
697 //----------------------------------------------- END NEW ITEMS
698
699 void DocumentModel::fillGroups()
700 {
701     HEXA_NS::Group *g     = NULL;
702     GroupItem      *gItem = NULL;
703     int nbGroup = _hexaDocument->countGroup();
704     for ( int i=0; i<nbGroup; ++i ){
705         g = _hexaDocument->getGroup(i);
706         //std::cout<<"getGroup => "<< i << std::endl;
707         gItem = new GroupItem(g);
708         gItem->setData( _entry, HEXA_DOC_ENTRY_ROLE );
709         _groupDirItem->appendRow(gItem);
710     }
711 }
712
713 void DocumentModel::fillMesh()
714 {
715     //   _lawDirItem
716     HEXA_NS::Law *l     = NULL;
717     LawItem      *lItem = NULL;
718     int nbLaw = _hexaDocument->countLaw();
719     for ( int i=0; i<nbLaw; ++i ){
720         l = _hexaDocument->getLaw(i);
721         lItem = new LawItem(l);
722         _lawDirItem->appendRow(lItem);
723     }
724
725     //   _propagationDirItem
726     HEXA_NS::Propagation *p     = NULL;
727     PropagationItem      *pItem = NULL;
728     int nbPropagation = _hexaDocument->countPropagation();
729     for ( int i=0; i<nbPropagation; ++i ){
730         p = _hexaDocument->getPropagation(i);
731         pItem = new PropagationItem(p);
732         pItem->setText(QString("Propagation%1").arg(i) );
733         pItem->setData( _entry, HEXA_DOC_ENTRY_ROLE );
734         _propagationDirItem->appendRow(pItem);
735     }
736 }
737
738 HEXA_NS::Hexa* DocumentModel::getQuadHexa(HEXA_NS::Quad* quad)
739 {
740     HEXA_NS::Hexa* hexa;
741     int nbHexa = _hexaDocument->countHexa();
742     for ( int i=0; i<nbHexa; ++i ){
743         hexa = _hexaDocument->getHexa(i);
744         if (hexa->findQuad(quad) > -1) return hexa;
745     }
746     return NULL;
747 }
748
749
750 Qt::ItemFlags DocumentModel::flags(const QModelIndex &index) const
751 {
752     Qt::ItemFlags flags;
753
754     if (!index.isValid()) return Qt::ItemIsEnabled;
755
756     if ( _disallowEdition ){
757         return QAbstractItemModel::flags(index) | Qt::ItemFlags( ~Qt::ItemIsEditable );
758     } else {
759         return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
760     }
761 }
762
763 void DocumentModel::allowEdition()
764 {
765     _disallowEdition = false;
766 }
767
768 void DocumentModel::disallowEdition()
769 {
770     _disallowEdition = true;
771 }
772
773 void DocumentModel::allowDataSelectionOnly()
774 {
775     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
776     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
777     _quadItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
778     _hexaItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
779
780     _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
781     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
782     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
783
784     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
785     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
786     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
787 }
788
789 void DocumentModel::allowVertexSelectionOnly()
790 {
791     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable);
792     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
793     _quadItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
794     _hexaItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
795
796     _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
797     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
798     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
799
800     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
801     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
802     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
803
804     //     emit layoutChanged();
805 }
806
807 void DocumentModel::allowEdgeSelectionOnly()
808 {
809     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
810     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
811     _quadItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
812     _hexaItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
813
814     _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
815     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
816     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
817
818     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
819     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
820     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
821 }
822
823 void DocumentModel::allowQuadSelectionOnly()
824 {
825     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
826     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
827     _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
828     _hexaItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
829
830     _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
831     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
832     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
833
834     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
835     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
836     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
837 }
838
839 void DocumentModel::allowHexaSelectionOnly()
840 {
841     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
842     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
843     _quadItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
844     _hexaItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
845
846     _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
847     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
848     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
849
850     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
851     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
852     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
853 }
854
855 void DocumentModel::allowVectorSelectionOnly()
856 {
857     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
858     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
859     _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
860     _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
861
862     _vectorItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
863     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
864     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
865
866     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
867     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
868     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
869 }
870
871 void DocumentModel::allowCylinderSelectionOnly()
872 {
873     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
874     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
875     _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
876     _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
877
878     _vectorItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
879     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
880     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
881
882     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
883     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
884     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
885 }
886
887 void DocumentModel::allowPipeSelectionOnly()
888 {
889     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
890     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
891     _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
892     _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
893
894     _vectorItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
895     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
896     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
897
898     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
899     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
900     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
901 }
902
903 void DocumentModel::allowElementsSelectionOnly()
904 {
905     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
906     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
907     _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
908     _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
909
910     _vectorItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
911     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
912     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
913
914     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
915     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
916     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
917 }
918
919 /**********************************************************
920 void DocumentModel::allowCrossElementsSelectionOnly()
921 {
922     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
923     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
924     _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
925     _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
926
927     _vectorItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
928     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
929     _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
930
931     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
932     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
933     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
934 }
935  ********************************************************** */
936
937 void DocumentModel::allowLawSelectionOnly()
938 {
939     _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
940     _edgeItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
941     _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
942     _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
943
944     _vectorItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEnabled );
945     _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
946     _crossElementsItemFlags = Qt::ItemFlags( Qt::ItemIsEnabled );
947
948     _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
949     _lawItemFlags   = Qt::ItemFlags( ~Qt::ItemIsEditable );
950     _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
951 }
952
953
954 void DocumentModel::setName( const QModelIndex& iElt, const QString& name )
955 {
956     HEXA_NS::EltBase *elt = NULL;
957
958     switch ( data(iElt, HEXA_TREE_ROLE).toInt() ){
959     case GROUP_TREE :
960     {
961         HEXA_NS::Group* grp = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Group* >();
962         grp->setName( name.toLatin1().data() );
963         break;
964     }
965     case LAW_TREE :
966     {
967         HEXA_NS::Law* l = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Law* >();
968         l->setName( name.toLatin1().data() );
969         break;
970     }
971     //   case PROPAGATION_TREE : elt = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Propagation* >(); break;
972     default: elt = getHexaPtr(iElt);
973     }
974
975     if ( elt != NULL ) elt->setName( name.toStdString() );
976     setData( iElt, name );
977
978 }
979
980 bool DocumentModel::clearEltAssociations( const QModelIndex& iElt )
981 {
982     bool isOk = false;
983     HEXA_NS::EltBase *elt = getHexaPtr(iElt);
984
985     if ( elt != NULL ){
986         elt->clearAssociation();
987         setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
988         isOk = true;
989     }
990
991     return isOk;
992 }
993
994 void DocumentModel::clearAssociation(HEXA_NS::EnumElt& eltType)
995 {
996     if (_hexaDocument != NULL)
997         _hexaDocument->clearAssociation(eltType);
998
999     QModelIndex iElt;
1000     HEXA_NS::Vertex* vertex;
1001     HEXA_NS::Edge* edge;
1002     HEXA_NS::Quad* quad;
1003     int nbElts;
1004
1005     if (HEXABLOCKGUI::currentDocGView == NULL) return;
1006     PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
1007     PatternDataModel* pdm = HEXABLOCKGUI::currentDocGView->getPatternDataModel();
1008     if (pdsm == NULL || pdm == NULL) return;
1009
1010     //update associations in the model
1011     if (eltType == HEXA_NS::EL_VERTEX)
1012     {
1013         nbElts = _hexaDocument->countVertex();
1014         for (int i = 0; i < nbElts; ++i)
1015         {
1016             vertex = _hexaDocument->getVertex(i);
1017             iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(vertex)));
1018             if (iElt.isValid())
1019                 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
1020         }
1021     }
1022     else if (eltType == HEXA_NS::EL_EDGE)
1023     {
1024         nbElts = _hexaDocument->countEdge();
1025         for (int i = 0; i < nbElts; ++i)
1026         {
1027             edge = _hexaDocument->getEdge(i);
1028             iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(edge)));
1029             if (iElt.isValid())
1030                 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
1031         }
1032     }
1033     else if (eltType == HEXA_NS::EL_QUAD)
1034     {
1035         nbElts = _hexaDocument->countQuad();
1036         for (int i = 0; i < nbElts; ++i)
1037         {
1038             quad = _hexaDocument->getQuad(i);
1039             iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(quad)));
1040             if (iElt.isValid())
1041                 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
1042         }
1043     }
1044 }
1045
1046
1047 QModelIndex DocumentModel::addVertex( double x, double y, double z )
1048 {
1049     QModelIndex vertexIndex;
1050
1051     HEXA_NS::Vertex* hv = _hexaDocument->addVertex(x, y, z);
1052     if (BadElement(hv)) return vertexIndex;
1053
1054     VertexItem* v = new VertexItem(hv, _entry);
1055     _vertexDirItem->appendRow(v);
1056     vertexIndex = v->index();
1057     emit patternDataChanged();
1058
1059     return vertexIndex;
1060 }
1061
1062 QModelIndex DocumentModel::addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 )
1063 {
1064     QModelIndex edgeIndex;
1065
1066     HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(i_v0);
1067     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(i_v1);
1068
1069     HEXA_NS::Edge* he = _hexaDocument->addEdge( hv0, hv1 );
1070     if ( BadElement(he) ) return edgeIndex;
1071
1072     EdgeItem* e = new EdgeItem(he, _entry);
1073     _edgeDirItem->appendRow(e);
1074     edgeIndex = e->index();
1075     emit patternDataChanged();
1076
1077     return edgeIndex;
1078 }
1079
1080 QModelIndex DocumentModel::addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec )
1081 {
1082     QModelIndex edgeIndex;
1083
1084     HEXA_NS::Vertex* hv   = getHexaPtr<HEXA_NS::Vertex*>(i_v);
1085     HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(i_vec);
1086
1087     if (hv == NULL || hvec == NULL) return edgeIndex;
1088
1089     HEXA_NS::Edge* he = _hexaDocument->addEdgeVector( hv, hvec );
1090     if ( BadElement(he) ) return edgeIndex;
1091
1092     HEXA_NS::Vertex* hv2 = he->getAval(); //the new vertex resulting from the creation of the edge
1093     if (hv2 == NULL) return edgeIndex;
1094
1095     //ADD the edge in the treeview
1096     EdgeItem* e = new EdgeItem(he, _entry);
1097     _edgeDirItem->appendRow(e);
1098     edgeIndex = e->index();
1099
1100     //The resulting Vertex
1101     VertexItem* v = new VertexItem(hv2, _entry);
1102     _vertexDirItem->appendRow(v);
1103
1104     emit patternDataChanged();
1105
1106     return edgeIndex;
1107 }
1108
1109 QModelIndex DocumentModel::addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
1110         const QModelIndex &i_v2, const QModelIndex &i_v3 )
1111 { //CS_TODO : gestion erreur
1112     QModelIndex quadIndex;
1113
1114     HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(i_v0);
1115     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(i_v1);
1116     HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(i_v2);
1117     HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(i_v3);
1118
1119     if ( hv0 && hv1 && hv2 && hv3 ){
1120         HEXA_NS::Quad* hq = _hexaDocument->addQuadVertices( hv0, hv1, hv2, hv3 );
1121         if ( BadElement(hq) ) return quadIndex;
1122
1123         QuadItem* q = new QuadItem(hq, _entry);
1124         _quadDirItem->appendRow(q);
1125         quadIndex = q->index();
1126         emit patternDataChanged();
1127     }
1128
1129     return quadIndex;
1130 }
1131
1132 QModelIndex DocumentModel::addQuadEdges( const QModelIndex &e0, const QModelIndex &e1,
1133         const QModelIndex &e2, const QModelIndex &e3 )
1134 { //CS_TODO
1135     QModelIndex quadIndex;
1136
1137     HEXA_NS::Edge* he0 = getHexaPtr<HEXA_NS::Edge*>(e0);
1138     HEXA_NS::Edge* he1 = getHexaPtr<HEXA_NS::Edge*>(e1);
1139     HEXA_NS::Edge* he2 = getHexaPtr<HEXA_NS::Edge*>(e2);
1140     HEXA_NS::Edge* he3 = getHexaPtr<HEXA_NS::Edge*>(e3);
1141
1142     if ( he0 && he1 && he2 && he3 ){
1143
1144         HEXA_NS::Quad* hq = _hexaDocument->addQuad( he0, he1, he2, he3 );
1145         if ( BadElement(hq) ) return quadIndex;
1146
1147         QuadItem* q = new QuadItem(hq, _entry);
1148         _quadDirItem->appendRow(q);
1149         quadIndex = q->index();
1150         emit patternDataChanged();
1151     }
1152
1153     return quadIndex;
1154 }
1155
1156 QModelIndex DocumentModel::addHexaVertices(
1157         const QModelIndex &iv0, const QModelIndex &iv1,
1158         const QModelIndex &iv2, const QModelIndex &iv3,
1159         const QModelIndex &iv4, const QModelIndex &iv5,
1160         const QModelIndex &iv6, const QModelIndex &iv7 )
1161 {
1162     QModelIndex iHexa;
1163
1164     HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1165     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1166     HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
1167     HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
1168     HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
1169     HEXA_NS::Vertex* hv5 = getHexaPtr<HEXA_NS::Vertex*>(iv5);
1170     HEXA_NS::Vertex* hv6 = getHexaPtr<HEXA_NS::Vertex*>(iv6);
1171     HEXA_NS::Vertex* hv7 = getHexaPtr<HEXA_NS::Vertex*>(iv7);
1172
1173     HEXA_NS::Hexa* hh = _hexaDocument->addHexaVertices( hv0, hv1, hv2, hv3,
1174             hv4, hv5, hv6, hv7 );
1175
1176     if ( BadElement(hh) ) return iHexa;
1177
1178     HexaItem* h = new HexaItem(hh, _entry);
1179     _hexaDirItem->appendRow(h);
1180     iHexa = h->index();
1181     emit patternDataChanged();
1182
1183     return iHexa;
1184 }
1185
1186 QModelIndex DocumentModel::addHexaQuad( const QModelIndex &i_q0, const QModelIndex &i_q1,
1187         const QModelIndex &i_q2,const QModelIndex &i_q3, const QModelIndex &i_q4, const QModelIndex &i_q5 )
1188 { //CS_TODO : gestion erreur
1189     QModelIndex hexaIndex;
1190
1191     HEXA_NS::Quad* hq0 = getHexaPtr<HEXA_NS::Quad*>(i_q0);
1192     HEXA_NS::Quad* hq1 = getHexaPtr<HEXA_NS::Quad*>(i_q1);
1193     HEXA_NS::Quad* hq2 = getHexaPtr<HEXA_NS::Quad*>(i_q2);
1194     HEXA_NS::Quad* hq3 = getHexaPtr<HEXA_NS::Quad*>(i_q3);
1195     HEXA_NS::Quad* hq4 = getHexaPtr<HEXA_NS::Quad*>(i_q4);
1196     HEXA_NS::Quad* hq5 = getHexaPtr<HEXA_NS::Quad*>(i_q5);
1197
1198     HEXA_NS::Hexa* hh = _hexaDocument->addHexa( hq0, hq1, hq2, hq3, hq4, hq5 );
1199     if ( BadElement(hh) ) return hexaIndex;
1200
1201     HexaItem* h = new HexaItem(hh, _entry);
1202     _hexaDirItem->appendRow(h);
1203     hexaIndex = h->index();
1204     emit patternDataChanged();
1205
1206     return hexaIndex;
1207 }
1208
1209 QModelIndex DocumentModel::addHexaQuads( const QModelIndexList &iquads)
1210 {
1211     QModelIndex hexaIndex;
1212
1213     HEXA_NS::Hexa* hh = NULL;
1214     HEXA_NS::Quad* hq0, *hq1, *hq2, *hq3, *hq4, *hq5 = NULL;
1215
1216     hq0 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(0));
1217     hq1 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(1));
1218     hq2 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(2));
1219     hq3 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(3));
1220     hq4 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(4));
1221     hq5 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(5));
1222
1223     if ( hq0 && hq1 && hq2 && hq3 && hq4 && hq5 )
1224         hh = _hexaDocument->addHexa( hq0, hq1, hq2, hq3, hq4, hq5 );
1225     else if ( hq0 && hq1 && hq2 && hq3 && hq4 )
1226         hh = _hexaDocument->addHexa5Quads( hq0, hq1, hq2, hq3, hq4 );
1227     else if ( hq0 && hq1 && hq2 && hq3 )
1228         hh = _hexaDocument->addHexa4Quads( hq0, hq1, hq2, hq3 );
1229     else if ( hq0 && hq1 && hq2)
1230         hh = _hexaDocument->addHexa3Quads( hq0, hq1, hq2 );
1231     else if ( hq0 && hq1 )
1232         hh = _hexaDocument->addHexa2Quads( hq0, hq1);
1233
1234     if ( BadElement(hh) ) return hexaIndex;
1235
1236     updateData();
1237     unsigned int nbRows = _hexaDirItem->rowCount();
1238     if (nbRows > 0)
1239         hexaIndex = _hexaDirItem->child(nbRows-1)->index();
1240
1241     return hexaIndex;
1242 }
1243
1244 QModelIndex DocumentModel::addVector( double dx, double dy, double dz )
1245 {
1246     QModelIndex vectorIndex;
1247
1248     HEXA_NS::Vector* hv = _hexaDocument->addVector(dx, dy, dz);
1249     if ( BadElement(hv) ) return vectorIndex; //Invalid index
1250
1251     VectorItem* v = new VectorItem(hv);
1252     _vectorDirItem->appendRow(v);
1253     vectorIndex = v->index();
1254
1255     return vectorIndex;
1256 }
1257
1258 QModelIndex DocumentModel::addVectorVertices( const QModelIndex &iv0, const QModelIndex &iv1 )
1259 {
1260     QModelIndex iVec;
1261
1262     HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1263     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1264
1265     HEXA_NS::Vector* hvec = _hexaDocument->addVectorVertices( hv0, hv1 );
1266     if ( BadElement(hvec) ) return iVec;
1267
1268     VectorItem* vec = new VectorItem(hvec);
1269     _vectorDirItem->appendRow(vec);
1270     iVec = vec->index();
1271
1272     return iVec;
1273 }
1274
1275
1276 // ************  EDIT HEXABLOCK MODEL ************
1277
1278 bool DocumentModel::updateVertex( const QModelIndex& ivertex, double x, double y, double z )
1279 {
1280     bool ret = false;
1281
1282     HEXA_NS::Vertex* hVertex = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1283
1284     if ( hVertex ){
1285 //        hVertex->setName( name.toStdString() );
1286         hVertex->setX ( x );
1287         hVertex->setY ( y );
1288         hVertex->setZ ( z );
1289         emit patternDataChanged();
1290         ret = true;
1291     }
1292
1293     return ret;
1294 }
1295
1296 bool DocumentModel::removeHexa( const QModelIndex& ihexa )
1297 {
1298     HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1299
1300     int r = _hexaDocument->removeHexa( hHexa );
1301     if ( r == HOK ){
1302         updateData();
1303         return true;
1304     }
1305
1306     return false;
1307 }
1308
1309 bool DocumentModel::removeConnectedHexa( const QModelIndex& ihexa )
1310 {
1311     HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1312
1313     int r = _hexaDocument->removeConnectedHexa( hHexa );
1314     if ( r == HOK ){
1315         updateData();
1316         return true;
1317     }
1318
1319     return false;
1320 }
1321
1322 bool DocumentModel::mergeVertices( const QModelIndex &iv0, const QModelIndex &iv1 ) //CS_TODO : impact sur le model?
1323 {
1324     HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1325     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1326
1327     int r = _hexaDocument->mergeVertices( hv0, hv1 );
1328     if ( r == HOK ){
1329         updateData(); //CS_TODO more or less?
1330         return true;
1331     }
1332
1333     return false;
1334 }
1335
1336 bool DocumentModel::mergeEdges( const QModelIndex &ie0, const QModelIndex &ie1,
1337         const QModelIndex &iv0, const QModelIndex &iv1 )
1338 //CS_TODO : impact sur le model?
1339 {
1340     HEXA_NS::Edge* he0 = getHexaPtr<HEXA_NS::Edge*>(ie0);
1341     HEXA_NS::Edge* he1 = getHexaPtr<HEXA_NS::Edge*>(ie1);
1342
1343     HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1344     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1345
1346     //Merge
1347     int r = _hexaDocument->mergeEdges( he0, he1, hv0, hv1 );
1348     if ( r == HOK ){
1349         updateData();
1350         return true;
1351     }
1352
1353     return false;
1354 }
1355
1356 bool DocumentModel::mergeQuads( const QModelIndex& iquad0, const QModelIndex& iquad1,
1357         const QModelIndex& iv0, const QModelIndex& iv1,
1358         const QModelIndex& iv2, const QModelIndex& iv3 )
1359 {
1360     HEXA_NS::Quad* hquad0 = data(iquad0, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1361     HEXA_NS::Quad* hquad1 = data(iquad1, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1362
1363     HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1364     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1365     HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
1366     HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
1367
1368     int r = _hexaDocument->mergeQuads( hquad0, hquad1, hv0, hv1, hv2, hv3 );
1369     if ( r == HOK ){
1370         updateData();
1371         return true;
1372     }
1373
1374     return false;
1375 }
1376
1377 //
1378 QModelIndex DocumentModel::disconnectVertex( const QModelIndex& ihexa, const QModelIndex& ivertex )
1379 {
1380     QModelIndex iElts;
1381
1382     HEXA_NS::Hexa*   hHexa   = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1383     HEXA_NS::Vertex* hVertex = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1384
1385     HEXA_NS::Elements* hElts = _hexaDocument->disconnectVertex( hHexa, hVertex );
1386     if ( BadElement(hElts) ) return iElts;
1387
1388     updateData(); //CS_TO_CHECK
1389     ElementsItem* elts = new ElementsItem(hElts);
1390     _elementsDirItem->appendRow(elts);
1391     iElts = elts->index();
1392
1393     return iElts;
1394 }
1395
1396 QModelIndex DocumentModel::disconnectEdge( const QModelIndex& ihexa, const QModelIndex& iedge )
1397 {
1398     QModelIndex iElts;
1399
1400     HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1401     HEXA_NS::Edge* hEdge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1402
1403     HEXA_NS::Elements* hElts = _hexaDocument->disconnectEdge( hHexa, hEdge );
1404     if ( BadElement(hElts) ) return iElts;
1405
1406     updateData(); //CS_TO_CHECK
1407     ElementsItem* elts = new ElementsItem(hElts);
1408     _elementsDirItem->appendRow(elts);
1409     iElts = elts->index();
1410
1411     return iElts;
1412 }
1413
1414
1415 QModelIndex DocumentModel::disconnectEdges( const QModelIndexList& ihexas, const QModelIndexList& iedges )
1416 {
1417     QModelIndex iElts;
1418
1419     HEXA_NS::Hexas hHexas;
1420     HEXA_NS::Edges hEdges;
1421
1422     //edges list
1423     HEXA_NS::Edge* hedge = NULL;
1424     foreach( const QModelIndex& iedge, iedges ){
1425         hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1426         hEdges.push_back( hedge );
1427     }
1428
1429     //hexas list
1430     HEXA_NS::Hexa* hhexa = NULL;
1431     foreach( const QModelIndex& ihexa, ihexas ){
1432         hhexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1433         hHexas.push_back( hhexa );
1434     }
1435
1436
1437     HEXA_NS::Elements* hElts = _hexaDocument->disconnectEdges( hHexas, hEdges );
1438     if ( BadElement(hElts) ) return iElts;
1439
1440     updateData(); //CS_TO_CHECK
1441     ElementsItem* elts = new ElementsItem(hElts);
1442     _elementsDirItem->appendRow(elts);
1443     iElts = elts->index();
1444
1445     return iElts;
1446 }
1447
1448
1449 QModelIndex DocumentModel::disconnectQuad( const QModelIndex& ihexa, const QModelIndex& iquad )
1450 {
1451     QModelIndex iElts;
1452
1453     HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1454     HEXA_NS::Quad* hQuad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1455
1456     HEXA_NS::Elements* hElts = _hexaDocument->disconnectQuad( hHexa, hQuad );
1457     if ( BadElement(hElts) ) return iElts;
1458
1459     updateData(); //CS_TO_CHECK
1460     ElementsItem* elts = new ElementsItem(hElts);
1461     _elementsDirItem->appendRow(elts);
1462     iElts = elts->index();
1463
1464     return iElts;
1465 }
1466
1467
1468 QModelIndex DocumentModel::makeTranslation( const QModelIndex& ielts, const QModelIndex& ivec )
1469 {
1470     QModelIndex iElts;
1471
1472     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1473     HEXA_NS::Vector*   hVec  = getHexaPtr<HEXA_NS::Vector*>(ivec);
1474
1475     HEXA_NS::Elements* hNewElts = _hexaDocument->makeTranslation( hElts, hVec );
1476     if ( BadElement(hNewElts) ) return iElts;
1477
1478     updateData(); //CS_TODO  more or less?
1479     ElementsItem* eltsItem = new ElementsItem(hNewElts);
1480     _elementsDirItem->appendRow(eltsItem);
1481     iElts = eltsItem->index();
1482
1483     return iElts;
1484 }
1485
1486
1487
1488 QModelIndex DocumentModel::makeScale( const QModelIndex& ielts, const QModelIndex& ivex, double k )
1489 {
1490     QModelIndex iElts;
1491
1492     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1493     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1494
1495     HEXA_NS::Elements* hNewElts = _hexaDocument->makeScale( hElts, hVex, k );
1496     if ( BadElement(hNewElts) ) return iElts;
1497
1498     updateData(); //CS_TODO  more or less?
1499     ElementsItem* eltsItem = new ElementsItem(hNewElts);
1500     _elementsDirItem->appendRow(eltsItem);
1501     iElts = eltsItem->index();
1502
1503     return iElts;
1504 }
1505
1506 QModelIndex DocumentModel::makeRotation( const QModelIndex& ielts,
1507         const QModelIndex& iv,
1508         const QModelIndex& ivec, double angle )
1509 {
1510     QModelIndex iElts;
1511
1512     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1513     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(iv);
1514     HEXA_NS::Vector*   hVec  = getHexaPtr<HEXA_NS::Vector*>(ivec);
1515
1516     HEXA_NS::Elements* hNewElts = _hexaDocument->makeRotation( hElts, hVex, hVec, angle );
1517     if ( BadElement(hNewElts) ) return iElts;
1518
1519     updateData(); //CS_TODO  more or less?
1520     ElementsItem* eltsItem = new ElementsItem(hNewElts);
1521     _elementsDirItem->appendRow(eltsItem);
1522     iElts = eltsItem->index();
1523
1524     return iElts;
1525 }
1526
1527
1528 QModelIndex DocumentModel::makeSymmetryPoint( const QModelIndex& ielts, const QModelIndex& iv )
1529 {
1530     QModelIndex iElts;
1531
1532     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1533     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(iv);
1534
1535     HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryPoint (hElts, hVex);
1536     if ( BadElement(hNewElts) ) return iElts;
1537
1538     updateData(); //CS_TODO  more or less?
1539     ElementsItem* eltsItem = new ElementsItem(hNewElts);
1540     _elementsDirItem->appendRow(eltsItem);
1541     iElts = eltsItem->index();
1542
1543     return iElts;
1544 }
1545
1546
1547 QModelIndex DocumentModel::makeSymmetryLine( const QModelIndex& ielts,
1548         const QModelIndex& iv,
1549         const QModelIndex& ivec )
1550 {
1551     QModelIndex iElts;
1552
1553     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1554     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(iv);
1555     HEXA_NS::Vector*   hVec  = getHexaPtr<HEXA_NS::Vector*>(ivec);
1556
1557
1558     HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryLine( hElts, hVex, hVec );
1559     if ( BadElement(hNewElts) ) return iElts;
1560
1561     updateData(); //CS_TODO  more or less?
1562     ElementsItem* eltsItem = new ElementsItem(hNewElts);
1563     _elementsDirItem->appendRow(eltsItem);
1564     iElts = eltsItem->index();
1565
1566     return iElts;
1567 }
1568
1569
1570 QModelIndex DocumentModel::makeSymmetryPlane( const QModelIndex& ielts, const QModelIndex& iv, const QModelIndex& ivec )
1571 {
1572     QModelIndex iElts;
1573
1574     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1575     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(iv);
1576     HEXA_NS::Vector*   hVec  = getHexaPtr<HEXA_NS::Vector*>(ivec);
1577
1578     HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryPlane( hElts, hVex, hVec );
1579     if ( BadElement(hNewElts) ) return iElts;
1580
1581     updateData(); //CS_TODO  more or less?
1582     ElementsItem* eltsItem = new ElementsItem(hNewElts);
1583     _elementsDirItem->appendRow(eltsItem);
1584     iElts = eltsItem->index();
1585
1586     return iElts;
1587 }
1588
1589
1590 bool DocumentModel::performTranslation( const QModelIndex& ielts, const QModelIndex& ivec )
1591 {
1592     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1593     HEXA_NS::Vector*   hVec  = getHexaPtr<HEXA_NS::Vector*>(ivec);
1594
1595     int r = _hexaDocument->performTranslation (hElts, hVec);
1596     if ( r == HOK ){ //Job well done?
1597         updateData();
1598         return true;
1599     }
1600
1601     return false;
1602 }
1603
1604
1605 //
1606 bool DocumentModel::performScale( const QModelIndex& ielts, const QModelIndex& ivex, double k )
1607 {
1608     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1609     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1610
1611     int r = _hexaDocument->performScale (hElts, hVex, k);
1612     if ( r == HOK ){
1613         updateData();
1614         return true;
1615     }
1616
1617     return false;
1618 }
1619
1620 //
1621 bool DocumentModel::performRotation( const QModelIndex& ielts, const QModelIndex& ivex, const QModelIndex& ivec, double angle )
1622 {
1623     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1624     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1625     HEXA_NS::Vector*   hVec  = getHexaPtr<HEXA_NS::Vector*>(ivec);
1626
1627     int r = _hexaDocument-> performRotation( hElts, hVex, hVec, angle );
1628     if ( r == HOK ){
1629         updateData();
1630         return true;
1631     }
1632
1633     return false;
1634 }
1635
1636
1637 //
1638 bool DocumentModel::performSymmetryPoint( const QModelIndex& ielts, const QModelIndex& ivex )
1639 {
1640     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1641     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1642
1643     int r = _hexaDocument->performSymmetryPoint( hElts, hVex );
1644     if ( r == HOK ){
1645         updateData();
1646         return true;
1647     }
1648
1649     return false;
1650 }
1651
1652
1653 bool DocumentModel::performSymmetryLine( const QModelIndex& ielts, const QModelIndex& ivex, const QModelIndex& ivec )
1654 {
1655     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1656     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1657     HEXA_NS::Vector*   hVec  = getHexaPtr<HEXA_NS::Vector*>(ivec);
1658
1659     int r = _hexaDocument->performSymmetryLine( hElts, hVex, hVec );
1660     if ( r == HOK ){
1661         updateData();
1662         return true;
1663     }
1664
1665     return false;
1666 }
1667
1668
1669 bool DocumentModel::performSymmetryPlane( const QModelIndex& ielts,
1670         const QModelIndex& ivex,
1671         const QModelIndex& ivec )
1672 {
1673     HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1674     HEXA_NS::Vertex*   hVex  = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1675     HEXA_NS::Vector*   hVec  = getHexaPtr<HEXA_NS::Vector*>(ivec);
1676
1677     int r = _hexaDocument->performSymmetryPlane( hElts, hVex, hVec );
1678     if ( r == HOK ){
1679         updateData();
1680         return true;
1681     }
1682
1683     return false;
1684 }
1685
1686 QModelIndex DocumentModel::replace( const QModelIndexList& iquadsPattern,
1687         const QModelIndex& ip1, const QModelIndex& ic1,
1688         const QModelIndex& ip2, const QModelIndex& ic2,
1689         const QModelIndex& ip3, const QModelIndex& ic3 )
1690 {
1691     QModelIndex ielts;
1692
1693     HEXA_NS::Vertex* hp1 = getHexaPtr<HEXA_NS::Vertex*>(ip1);
1694     HEXA_NS::Vertex* hc1 = getHexaPtr<HEXA_NS::Vertex*>(ic1);
1695     HEXA_NS::Vertex* hp2 = getHexaPtr<HEXA_NS::Vertex*>(ip2);
1696     HEXA_NS::Vertex* hc2 = getHexaPtr<HEXA_NS::Vertex*>(ic2);
1697     HEXA_NS::Vertex* hp3 = getHexaPtr<HEXA_NS::Vertex*>(ip3);
1698     HEXA_NS::Vertex* hc3 = getHexaPtr<HEXA_NS::Vertex*>(ic3);
1699
1700     HEXA_NS::Quads   hquads;
1701     HEXA_NS::Quad*   hquad = NULL;
1702     foreach( const QModelIndex& iquad, iquadsPattern ){
1703         hquad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1704         hquads.push_back( hquad );
1705     }
1706
1707     HEXA_NS::Elements* helts = _hexaDocument->replace( hquads,
1708                                                        hp1, hc1, hp2, hc2, hp3, hc3 );
1709     if ( BadElement(helts) ) return ielts;
1710
1711     updateData();
1712     ElementsItem* eltsItem = new ElementsItem(helts);
1713     _elementsDirItem->appendRow(eltsItem);
1714     ielts = eltsItem->index();
1715
1716     return ielts;
1717 }
1718
1719 QModelIndex DocumentModel::replace( const QModelIndexList& iquads_source,
1720                                     const QModelIndexList& iquads_dest,
1721                                     const QModelIndex& ip1_source, const QModelIndex& ic1_dest,
1722                                     const QModelIndex& ip2_source, const QModelIndex& ic2_dest,
1723                                     const QModelIndex& ip3_source, const QModelIndex& ic3_dest)
1724 {
1725     QModelIndex ielts;
1726
1727     HEXA_NS::Vertex* hp1 = getHexaPtr<HEXA_NS::Vertex*>(ip1_source);
1728     HEXA_NS::Vertex* hp2 = getHexaPtr<HEXA_NS::Vertex*>(ip2_source);
1729     HEXA_NS::Vertex* hp3 = getHexaPtr<HEXA_NS::Vertex*>(ip3_source);
1730     HEXA_NS::Vertex* hc1 = getHexaPtr<HEXA_NS::Vertex*>(ic1_dest);
1731     HEXA_NS::Vertex* hc2 = getHexaPtr<HEXA_NS::Vertex*>(ic2_dest);
1732     HEXA_NS::Vertex* hc3 = getHexaPtr<HEXA_NS::Vertex*>(ic3_dest);
1733
1734     HEXA_NS::Quads   hquads_source, hquads_dest;
1735     HEXA_NS::Quad*   hquad = NULL;
1736     foreach( const QModelIndex& iquad, iquads_source ){
1737         hquad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1738         hquads_source.push_back( hquad );
1739     }
1740
1741     foreach( const QModelIndex& iquad, iquads_dest) {
1742         hquad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1743         hquads_dest.push_back(hquad);
1744     }
1745
1746     HEXA_NS::Elements* helts = _hexaDocument->replaceHexas( hquads_source,
1747                                                             hquads_dest,
1748                                                             hp1, hc1, hp2, hc2, hp3, hc3);
1749     if ( BadElement(helts) )
1750         return ielts;
1751
1752     updateData();
1753     ElementsItem* eltsItem = new ElementsItem(helts);
1754     _elementsDirItem->appendRow(eltsItem);
1755     ielts = eltsItem->index();
1756
1757     return ielts;
1758 }
1759
1760 QModelIndex DocumentModel::getGeomModelIndex(QString& id) const
1761 {
1762     QModelIndex result;
1763     PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1764
1765     // ** get the model index of the geom element having this ID
1766     HEXA_NS::SubShape* eltPtr = getGeomPtr(id);
1767     HEXA_NS::VertexShape* geomVertex = dynamic_cast<HEXA_NS::VertexShape*>(eltPtr);
1768     HEXA_NS::EdgeShape* geomEdge = dynamic_cast<HEXA_NS::EdgeShape*>(eltPtr);
1769     HEXA_NS::FaceShape* geomFace = dynamic_cast<HEXA_NS::FaceShape*>(eltPtr);
1770     if (geomVertex != NULL)
1771         result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomVertex));
1772     if (geomEdge != NULL)
1773         result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomEdge));
1774     if (geomFace != NULL)
1775         result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomFace));
1776
1777     return result;
1778 }
1779
1780 QMultiMap< QString, int >     DocumentModel::getAssocShapesIds(const QModelIndex& dataIndex)
1781 {
1782    QMultiMap< QString, int > result;
1783    HEXA_NS::NewShape* mainShape;
1784    HEXA_NS::VertexShape* node;
1785    HEXA_NS::EdgeShape* line;
1786    HEXA_NS::FaceShape* face;
1787    QString shapeName;
1788    int subid;
1789
1790    PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
1791    QModelIndexList assocsInd = pdsm->getGeomAssociations(dataIndex);
1792    foreach( const QModelIndex& anAssoc, assocsInd )
1793    {
1794       node = getHexaPtr<HEXA_NS::VertexShape*>(anAssoc);
1795       line = getHexaPtr<HEXA_NS::EdgeShape*>(anAssoc);
1796       face = getHexaPtr<HEXA_NS::FaceShape*>(anAssoc);
1797
1798       if (node != NULL)
1799          {
1800             mainShape = node->getParentShape();
1801             if (mainShape != NULL)
1802                {
1803                   shapeName = mainShape->getName();
1804                   subid = node->getIdent();
1805                }
1806          }
1807       else if (line != NULL)
1808          {
1809             mainShape = line->getParentShape();
1810             if (mainShape != NULL)
1811                {
1812                   shapeName = mainShape->getName();
1813                   subid = line->getIdent();
1814                }
1815          }
1816       else if (face != NULL)
1817          {
1818             mainShape = face->getParentShape();
1819             if (mainShape != NULL)
1820                {
1821                   shapeName = mainShape->getName();
1822                   subid = face->getIdent();
1823                }
1824          }
1825
1826       if (!shapeName.isEmpty())
1827          result.insert( shapeName, subid );
1828
1829       shapeName = QString();
1830    }
1831    return result;
1832 }
1833
1834 bool DocumentModel::setVertexAssociation( const QModelIndex& iVertex, double x, double y, double z)
1835 {
1836     HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex *>(iVertex);
1837
1838     if (vertex == NULL || _hexaDocument == NULL || vertex->setAssociation(x, y, z) != HOK)
1839         return false;
1840
1841     HEXA_NS::VertexShape* assoc = vertex->getAssociation();
1842     if (assoc != NULL)
1843     {
1844         HEXA_NS::NewShape* mainSh = assoc->getParentShape();
1845         setData( iVertex, QVariant::fromValue(QString(mainSh->getName())+","+QString::number(assoc->getIdent())+";"), HEXA_ASSOC_ENTRY_ROLE );
1846     }
1847
1848     return true;
1849 }
1850
1851 bool DocumentModel::setVertexAssociation( const QModelIndex& iVertex, const QModelIndex& iGeomVertex)
1852 {
1853     //parameters control
1854     QString newAssoc;
1855     HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex *>(iVertex);
1856     HEXA_NS::VertexShape* geomVertex = getHexaPtr<HEXA_NS::VertexShape*>(iGeomVertex);
1857     if (_hexaDocument == NULL || vertex == NULL || geomVertex == NULL) return false;
1858     HEXA_NS::NewShape* mainShape = geomVertex->getParentShape();
1859     if (mainShape == NULL) return false;
1860
1861     //add association
1862     if (vertex->setAssociation(geomVertex) != HOK)
1863         return false;
1864
1865     //update association state in the model
1866     newAssoc =  QString(mainShape->getName()) + "," + QString::number(geomVertex->getIdent()) + ";";
1867     setData( iVertex, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1868
1869     return true;
1870 }
1871
1872 bool DocumentModel::addEdgeAssociation( const QModelIndex& iEdge, const QModelIndex& iGeomEdge, double start, double end)
1873 {
1874     //parameters control
1875     QString currentAssoc, newAssoc;
1876     HEXA_NS::Edge* edge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
1877     HEXA_NS::EdgeShape* geomEdge = getHexaPtr<HEXA_NS::EdgeShape*>(iGeomEdge);
1878     if (_hexaDocument == NULL || edge == NULL ||
1879             geomEdge == NULL || start > end) return false;
1880     HEXA_NS::NewShape* mainShape = geomEdge->getParentShape();
1881     if (mainShape == NULL) return false;
1882
1883     //add association in the engine side
1884     if (edge->addAssociation(geomEdge, start, end) != HOK)
1885         return false;
1886
1887     //add/update association in the model side (UI)
1888     currentAssoc = data(iEdge, HEXA_ASSOC_ENTRY_ROLE).toString();
1889     newAssoc = QString(mainShape->getName()) + "," + QString::number(geomEdge->getIdent()) + ";";
1890     if (!currentAssoc.isEmpty()) newAssoc = currentAssoc + newAssoc;
1891
1892     setData( iEdge, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1893
1894     return true;
1895 }
1896
1897
1898 bool DocumentModel::addQuadAssociation (const QModelIndex& iQuad, const QModelIndex& iGeomFace)
1899 {
1900     //parameters control
1901     QString currentAssoc, newAssoc;
1902     HEXA_NS::Quad* quad = getHexaPtr<HEXA_NS::Quad*>(iQuad);
1903     HEXA_NS::FaceShape* geomFace = getHexaPtr<HEXA_NS::FaceShape*>(iGeomFace);
1904     if (_hexaDocument == NULL || quad == NULL || geomFace == NULL)
1905         return false;
1906     HEXA_NS::NewShape* mainShape = geomFace->getParentShape();
1907     if (mainShape == NULL) return false;
1908
1909     //add association
1910     if (quad->addAssociation(geomFace) != HOK)
1911         return false;
1912
1913     //update association
1914     currentAssoc = data( iQuad, HEXA_ASSOC_ENTRY_ROLE).toString();
1915     newAssoc = QString(mainShape->getName()) + "," + QString::number(geomFace->getIdent()) + ";";
1916     if (!currentAssoc.isEmpty()) newAssoc = currentAssoc + newAssoc;
1917     setData( iQuad, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1918
1919     return true;
1920 }
1921
1922
1923 QModelIndex DocumentModel::getVertexAssociation(const QModelIndex& iVertex)
1924 {
1925     HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1926     if (vertex == NULL)
1927         return QModelIndex();
1928
1929     //get the associated geom vertex
1930     HEXA_NS::VertexShape* geomVertex = vertex->getAssociation();
1931     if (geomVertex == NULL)
1932         return QModelIndex();
1933
1934     //convert geom vertex to qmodelindex
1935     PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1936     if (pgsm == NULL)
1937         return QModelIndex();
1938
1939     return pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(geomVertex));
1940 }
1941
1942
1943 QModelIndexList DocumentModel::getEdgeAssociations(const QModelIndex& iEdge)
1944 {
1945     QModelIndexList result;
1946     HEXA_NS::Edge* edge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
1947     if (edge == NULL) return result;
1948
1949     HEXA_NS::EdgeShape* geomEdge;
1950     HEXA_NS::AssoEdge* anEdgeAssoc;
1951
1952     PatternGeomSelectionModel* pGSModel = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1953     int nbAssocs = edge->countAssociation();
1954     for (int i = 0; i < nbAssocs; ++i)
1955     {
1956         anEdgeAssoc = edge->getAssociation(i);
1957         if (anEdgeAssoc == NULL) continue;
1958         geomEdge = anEdgeAssoc->getEdgeShape();
1959         if (geomEdge == NULL) continue;
1960         result << pGSModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomEdge));
1961     }
1962
1963     return result;
1964 }
1965
1966
1967 QModelIndexList DocumentModel::getQuadAssociations(const QModelIndex& iQuad)
1968 {
1969     QModelIndexList result;
1970     QModelIndex geomQuadIndex;
1971     HEXA_NS::Quad* quad = getHexaPtr<HEXA_NS::Quad*>(iQuad);
1972     if (quad == NULL) return result;
1973
1974     if (HEXABLOCKGUI::currentDocGView == NULL) return result;
1975     PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1976     PatternGeomModel* pgm = HEXABLOCKGUI::currentDocGView->getPatternGeomModel();
1977     if (pgsm == NULL || pgm == NULL) return result;
1978
1979     HEXA_NS::FaceShape* geomFace;
1980
1981     int nbAssocs = quad->countAssociation();
1982     for (int i = 0; i < nbAssocs; ++i)
1983     {
1984         geomFace = quad->getAssociation(i);
1985         if (geomFace == NULL) continue;
1986
1987         geomQuadIndex = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomFace) );
1988         result << geomQuadIndex;
1989     }
1990
1991     return result;
1992 }
1993
1994
1995 bool DocumentModel::associateOpenedLine( const QModelIndexList& iedges,
1996         HEXA_NS::NewShapes shapes,
1997         HEXA_NS::IntVector subIds,
1998         double pstart,
1999         double pend )
2000 {
2001
2002     HEXA_NS::Edges  mline;
2003
2004     HEXA_NS::Edge* hedge = NULL;
2005     foreach( const QModelIndex& iedge, iedges ){
2006         hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
2007         if (hedge != NULL)
2008             mline.push_back( hedge );
2009     }
2010
2011     int err = _hexaDocument->associateOpenedLine( mline, shapes, subIds, pstart, pend );
2012     if ( err == HOK ){
2013         updateData();
2014         return true;
2015     }
2016     return false;
2017 }
2018
2019 bool DocumentModel::associateClosedLine( const  QModelIndex& ivertex,
2020         const  QModelIndexList& iedges,
2021         HEXA_NS::NewShapes shapes,
2022         HEXA_NS::IntVector subIds,
2023         double pstart,
2024         bool   inv )
2025 {
2026     HEXA_NS::Vertex* mfirst = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
2027     HEXA_NS::Edges   mline;
2028
2029     HEXA_NS::Edge* hedge = NULL;
2030     foreach( const QModelIndex& iedge, iedges ){
2031         hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
2032         if (hedge != NULL)
2033             mline.push_back( hedge );
2034     }
2035
2036     int err = _hexaDocument->associateClosedLine( mfirst, mline, shapes, subIds, pstart, inv);
2037     if ( err == HOK ){
2038         updateData();
2039         return true;
2040     }
2041     return false;
2042 }
2043
2044 // ************  GROUPS  ************
2045 //
2046 QModelIndex DocumentModel::addGroup( const QString& name, Group kind )
2047 {
2048     QModelIndex iGroup;
2049
2050     HEXA_NS::Group* hGroup = _hexaDocument->addGroup( name.toLocal8Bit().constData(), kind );
2051     if ( hGroup == NULL ) return iGroup;
2052
2053     GroupItem* groupItem = new GroupItem(hGroup);
2054     groupItem->setData( _entry, HEXA_DOC_ENTRY_ROLE );
2055     _groupDirItem->appendRow(groupItem);
2056     iGroup = groupItem->index();
2057
2058     return iGroup;
2059 }
2060
2061
2062 bool DocumentModel::removeGroup( const QModelIndex& igrp )
2063 {
2064     HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2065     int r = _hexaDocument->removeGroup ( hGroup );
2066
2067     if ( r == HOK ){
2068         removeRow( igrp.row(), igrp.parent());
2069         return true;
2070     }
2071
2072     return false;
2073 }
2074
2075
2076 QModelIndexList DocumentModel::getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const
2077 {
2078     QModelIndexList iElements;
2079
2080     HEXA_NS::Group* g = iGroup.data(HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2081     if ( g == NULL ) return iElements;
2082
2083     QModelIndexList iFound;
2084     QVariant q;
2085     HEXA_NS::EltBase* eltBase = NULL;
2086     int nbElement = g->countElement();
2087     for ( int nr = 0; nr < nbElement; ++nr ){
2088         eltBase = g->getElement( nr );
2089         kind = g->getKind();
2090         switch ( kind ){
2091         case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: q = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
2092         case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: q = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
2093         case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: q = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
2094         case HEXA_NS::VertexNode: q = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
2095         }
2096         iFound = match( index(0, 0),
2097                 HEXA_DATA_ROLE,
2098                 q,
2099                 1,
2100                 Qt::MatchRecursive );
2101         if ( !iFound.isEmpty() )
2102             iElements << iFound[0];
2103     }
2104     return iElements;
2105 }
2106
2107 // 7.4 Boite: éditer un groupe
2108 void DocumentModel::setGroupName( const QModelIndex& igrp, const QString& name )
2109 {
2110     HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2111
2112     if ( hGroup ){
2113         hGroup->setName( name.toLocal8Bit().constData() );
2114         setData(igrp, QVariant::fromValue( name ) );
2115     }
2116 }
2117
2118 bool DocumentModel::addGroupElement( const QModelIndex& igrp, const QModelIndex& ielt )
2119 {
2120     HEXA_NS::Group*   hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2121     if (hGroup == NULL) return false;
2122
2123     HEXA_NS::EltBase* hElt   = NULL;
2124     switch ( hGroup->getKind() ){
2125     case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: hElt = getHexaPtr<HEXA_NS::Hexa*>(ielt); break;
2126     case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: hElt = getHexaPtr<HEXA_NS::Quad*>(ielt); break;
2127     case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: hElt = getHexaPtr<HEXA_NS::Edge*>(ielt); break;
2128     case HEXA_NS::VertexNode: hElt = getHexaPtr<HEXA_NS::Vertex*>(ielt); break;
2129     }
2130
2131     int res = HERR;
2132     if ( hElt != NULL )
2133         res = hGroup->addElement( hElt );
2134
2135     if ( res == HOK ) return true;
2136
2137     return false;
2138 }
2139
2140 bool DocumentModel::removeGroupElement( const QModelIndex& igrp, int nro )
2141 { //CS_TODO : remove child?
2142     HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2143     if (hGroup == NULL) return false;
2144
2145     if (hGroup->removeElement( nro ) == HOK) return true;
2146
2147     return false;
2148 }
2149
2150 bool DocumentModel::clearGroupElement( const QModelIndex& igrp )
2151 {
2152     HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2153
2154     if ( hGroup != NULL)
2155     {
2156         hGroup->clearElement();
2157         return true;
2158     }
2159     return false;
2160 }
2161
2162 // ************  LAWS  ************
2163
2164 //
2165 QModelIndex DocumentModel::addLaw( const QString& name, int nbnodes )
2166 {
2167     QModelIndex iLaw;
2168
2169     HEXA_NS::Law* hLaw = _hexaDocument->addLaw( name.toLocal8Bit().constData(), nbnodes );
2170     if ( BadElement(hLaw) ) return iLaw;
2171
2172     LawItem* lawItem = new LawItem(hLaw);
2173     _lawDirItem->appendRow(lawItem);
2174     iLaw = lawItem->index();
2175
2176     return iLaw;
2177 }
2178
2179 bool DocumentModel::setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type )
2180 {
2181     bool ret = false;
2182
2183     HEXA_NS::Law* hLaw = data(ilaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2184
2185     if ( hLaw ){
2186         int ok;
2187         ok = hLaw->setNodes( nbnodes );
2188         ( ok == HOK) ? ret = true : ret = false;
2189         ok = hLaw->setCoefficient( coeff );
2190         hLaw->setKind(type);
2191     }
2192
2193     return ret;
2194 }
2195
2196 //
2197 bool  DocumentModel::removeLaw( const QModelIndex& ilaw )
2198 {
2199     HEXA_NS::Law* hLaw = data(ilaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2200     int r = _hexaDocument->removeLaw( hLaw );
2201
2202     if ( r == HOK ){
2203         removeRow( ilaw.row(),  ilaw.parent());
2204         return true;
2205     }
2206
2207     return false;
2208 }
2209
2210 bool DocumentModel::setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way )
2211 {
2212     HEXA_NS::Propagation* hPropagation = data(iPropagation, HEXA_DATA_ROLE).value<HEXA_NS::Propagation *>();
2213     HEXA_NS::Law* hLaw = data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2214
2215     int r = hPropagation->setLaw( hLaw );
2216     hPropagation->setWay( way );
2217
2218     if ( r == HOK ) return true;
2219
2220     return false;
2221 }
2222
2223
2224 QModelIndexList DocumentModel::getPropagation( const QModelIndex& iPropagation ) const
2225 {
2226     QModelIndexList iEdges;
2227
2228     QModelIndexList iFound;
2229     HEXA_NS::Propagation* propa = iPropagation.data(HEXA_DATA_ROLE).value<HEXA_NS::Propagation *>();
2230     if ( propa == NULL ) return iEdges;
2231
2232     const HEXA_NS::Edges& edges = propa->getEdges();
2233     for ( HEXA_NS::Edges::const_iterator anEdge = edges.begin(), endIt = edges.end();
2234             anEdge != endIt;
2235             ++anEdge ){
2236         iFound = match( index(0, 0),
2237                 HEXA_DATA_ROLE,
2238                 QVariant::fromValue( *anEdge ),
2239                 1,
2240                 Qt::MatchRecursive);
2241         if ( !iFound.isEmpty() )
2242             iEdges << iFound[0];
2243     }
2244
2245     return iEdges;
2246 }
2247
2248 HEXA_NS::Document* DocumentModel::documentImpl()
2249 {
2250     return _hexaDocument;
2251 }
2252
2253 QString DocumentModel::documentEntry()
2254 {
2255     return _entry;
2256 }
2257
2258 // 8.3 Boite: éditer une loi  CS_TODO
2259 // (idem création)
2260
2261 /*****************************************************************
2262                       PatternDataModel
2263  *****************************************************************/
2264
2265 PatternDataModel::PatternDataModel( QObject * parent ) :
2266                               QSortFilterProxyModel( parent )
2267 {
2268     QString dataRegExp = QString("(%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12)").
2269             arg(VERTEX_TREE).arg(EDGE_TREE).arg(QUAD_TREE).arg(HEXA_TREE).arg(VECTOR_TREE).arg(ELEMENTS_TREE).
2270             arg(VERTEX_DIR_TREE).arg(EDGE_DIR_TREE).arg(QUAD_DIR_TREE).arg(HEXA_DIR_TREE).arg(VECTOR_DIR_TREE).
2271             arg(ELEMENTS_DIR_TREE);
2272
2273     setFilterRole(HEXA_TREE_ROLE);
2274     setFilterRegExp ( QRegExp(dataRegExp) );
2275 }
2276
2277 // *** Pour suppression des panneaux "Builder" et "Geometry" ****/
2278
2279 //PatternDataModel::PatternDataModel( QObject * parent ) :
2280 //                              QSortFilterProxyModel( parent )
2281 //{
2282 //    QString dataRegExp = QString("(%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12|%13|%14|%15|%16|%17|%18|%19|%20|%21|%22|%23|%24|%25|%26)").
2283 //            arg(VERTEX_TREE).arg(EDGE_TREE).arg(QUAD_TREE).arg(HEXA_TREE).
2284 //            arg(VERTEX_DIR_TREE).arg(EDGE_DIR_TREE).arg(QUAD_DIR_TREE).
2285 //            arg(HEXA_DIR_TREE).arg(VECTOR_TREE).arg(ELEMENTS_TREE).
2286 //            arg(VECTOR_DIR_TREE).arg(ELEMENTS_DIR_TREE).
2287 //            arg(IMPLICIT_SHAPES_TREE).arg(EXPLICIT_SHAPES_TREE).arg(CLOUD_OF_POINTS_TREE).
2288 //            arg(GEOMSHAPE_TREE).arg(GEOMPOINT_TREE).arg(GEOMEDGE_TREE).arg(GEOMFACE_TREE).
2289 //            arg(IMPLICIT_SHAPES_DIR_TREE).arg(EXPLICIT_SHAPES_DIR_TREE).arg(CLOUD_OF_POINTS_DIR_TREE).
2290 //            arg(GEOMSHAPE_DIR_TREE).arg(GEOMPOINT_DIR_TREE).arg(GEOMEDGE_DIR_TREE).arg(GEOMFACE_DIR_TREE);
2291 //
2292 //    setFilterRole(HEXA_TREE_ROLE);
2293 //    setFilterRegExp ( QRegExp(dataRegExp) );
2294 //}
2295
2296 // ****************
2297
2298 PatternDataModel::~PatternDataModel()
2299 {
2300 }
2301
2302 HEXA_NS::Document* PatternDataModel::documentImpl()
2303 {
2304     HEXA_NS::Document* doc = NULL;
2305     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2306     if (m) doc = m->documentImpl();
2307     return doc;
2308 }
2309
2310 QString PatternDataModel::documentEntry()
2311 {
2312     QString entry;
2313     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2314     if (m) entry = m->documentEntry();
2315     return entry;
2316 }
2317
2318 Qt::ItemFlags PatternDataModel::flags(const QModelIndex &index) const
2319 {
2320     Qt::ItemFlags flags;
2321
2322     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2323     if ( m != NULL ){
2324         flags = m->flags( mapToSource(index) );
2325     }
2326     return flags;
2327 }
2328
2329
2330 QVariant PatternDataModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2331 {
2332     if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2333         return QVariant( "Data" );
2334     } else {
2335         return QSortFilterProxyModel::headerData ( section, orientation, role );
2336     }
2337 }
2338
2339
2340 QStandardItem* PatternDataModel::itemFromIndex ( const QModelIndex & index ) const
2341 {
2342     QStandardItem *item = NULL;
2343     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2344     if ( m != NULL ){
2345         item = m->itemFromIndex( mapToSource(index) );
2346     }
2347     return item;
2348 }
2349
2350 //PatternBuilderModel::PatternBuilderModel( QObject * parent ) :
2351 //                              QSortFilterProxyModel( parent )
2352 //{
2353 //    QString builderRegExp =QString("(%1|%2|%3|%4|%5|%6)").
2354 //            arg(VECTOR_TREE).arg(ELEMENTS_TREE).
2355 //            arg(CROSSELEMENTS_TREE).arg(VECTOR_DIR_TREE).arg(ELEMENTS_DIR_TREE).arg(CROSSELEMENTS_DIR_TREE);
2356 //
2357 //    setFilterRole( HEXA_TREE_ROLE );
2358 //    setFilterRegExp ( QRegExp( builderRegExp ) );
2359 //}
2360
2361 //PatternBuilderModel::~PatternBuilderModel()
2362 //{
2363 //}
2364
2365 //Qt::ItemFlags PatternBuilderModel::flags(const QModelIndex &index) const
2366 //{
2367 //    Qt::ItemFlags flags;
2368 //
2369 //    DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2370 //    if ( m != NULL ){
2371 //        flags = m->flags( mapToSource(index) );
2372 //    }
2373 //    return flags;
2374 //}
2375
2376 //QVariant PatternBuilderModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2377 //{
2378 //    if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2379 //        return QVariant( "Builder" );
2380 //    } else {
2381 //        return QSortFilterProxyModel::headerData ( section, orientation, role );
2382 //    }
2383 //}
2384
2385 //QStandardItem* PatternBuilderModel::itemFromIndex ( const QModelIndex & index ) const
2386 //{
2387 //    QStandardItem *item = NULL;
2388 //    DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2389 //    if ( m != NULL ){
2390 //        item = m->itemFromIndex( mapToSource(index) );
2391 //    }
2392 //    return item;
2393 //}
2394
2395 //====================================================================
2396 //              PatternGeomModel
2397 //====================================================================
2398 PatternGeomModel::PatternGeomModel( QObject * parent ) :
2399                               QSortFilterProxyModel( parent )
2400 {
2401     QString builderRegExp =QString("(%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12|%13|%14)").
2402             arg(EXPLICIT_SHAPES_TREE).arg(IMPLICIT_SHAPES_TREE).arg(CLOUD_OF_POINTS_TREE).
2403             arg(GEOMSHAPE_TREE).arg(GEOMPOINT_TREE).arg(GEOMEDGE_TREE).arg(GEOMFACE_TREE).
2404             arg(EXPLICIT_SHAPES_DIR_TREE).arg(IMPLICIT_SHAPES_DIR_TREE).arg(CLOUD_OF_POINTS_DIR_TREE).
2405             arg(GEOMSHAPE_DIR_TREE).arg(GEOMPOINT_DIR_TREE).arg(GEOMEDGE_DIR_TREE).arg(GEOMFACE_DIR_TREE);
2406
2407     setFilterRole( HEXA_TREE_ROLE );
2408     setFilterRegExp ( QRegExp(builderRegExp ) );
2409 }
2410
2411 PatternGeomModel::~PatternGeomModel()
2412 {
2413 }
2414
2415 Qt::ItemFlags PatternGeomModel::flags(const QModelIndex &index) const
2416 {
2417     Qt::ItemFlags flags;
2418
2419     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2420     if ( m != NULL ){
2421         flags = m->flags( mapToSource(index) );
2422     }
2423     return flags;
2424 }
2425
2426 QVariant PatternGeomModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2427 {
2428     if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2429         return QVariant( "Geometry" );
2430     } else {
2431         return QSortFilterProxyModel::headerData ( section, orientation, role );
2432     }
2433 }
2434
2435 QStandardItem* PatternGeomModel::itemFromIndex ( const QModelIndex & index ) const
2436 {
2437     QStandardItem *item = NULL;
2438     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2439     if ( m != NULL ){
2440         item = m->itemFromIndex( mapToSource(index) );
2441     }
2442     return item;
2443 }
2444 //==============================================================
2445
2446
2447 AssociationsModel::AssociationsModel( QObject * parent ) :
2448                               QSortFilterProxyModel( parent )
2449 {
2450     QString assocRegExp;
2451
2452     setFilterRole( HEXA_TREE_ROLE );
2453     setFilterRegExp ( QRegExp(assocRegExp) );
2454 }
2455
2456 AssociationsModel::~AssociationsModel()
2457 {
2458 }
2459
2460 Qt::ItemFlags AssociationsModel::flags(const QModelIndex &index) const
2461 {
2462     Qt::ItemFlags flags;
2463
2464     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2465     if ( m != NULL ){
2466         flags = m->flags( mapToSource(index) );
2467     }
2468     return flags;
2469 }
2470
2471 QVariant AssociationsModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2472 {
2473     if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2474         return QVariant( "Associations" );
2475     } else {
2476         return QSortFilterProxyModel::headerData ( section, orientation, role );
2477     }
2478 }
2479
2480 QStandardItem* AssociationsModel::itemFromIndex ( const QModelIndex & index ) const
2481 {
2482     QStandardItem *item = NULL;
2483     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2484     if ( m != NULL ){
2485         item = m->itemFromIndex( mapToSource(index) );
2486     }
2487     return item;
2488 }
2489
2490 GroupsModel::GroupsModel( QObject * parent ) :
2491                               QSortFilterProxyModel( parent )
2492 {
2493     QString groupsRegExp =QString("(%1|%2)").arg(GROUP_TREE).arg(GROUP_DIR_TREE);
2494
2495     setFilterRole( HEXA_TREE_ROLE );
2496     setFilterRegExp ( QRegExp(groupsRegExp ) );
2497 }
2498
2499 GroupsModel::~GroupsModel()
2500 {
2501 }
2502
2503 Qt::ItemFlags GroupsModel::flags(const QModelIndex &index) const
2504 {
2505     Qt::ItemFlags flags;
2506
2507     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2508     if ( m != NULL ){
2509         flags = m->flags( mapToSource(index) );
2510     }
2511     return flags;
2512 }
2513
2514 QVariant GroupsModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2515 {
2516     if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2517         return QVariant( "Groups" );
2518     } else {
2519         return QSortFilterProxyModel::headerData ( section, orientation, role );
2520     }
2521 }
2522
2523 QStandardItem* GroupsModel::itemFromIndex ( const QModelIndex & index ) const
2524 {
2525     QStandardItem *item = NULL;
2526     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2527     if ( m != NULL ){
2528         item = m->itemFromIndex( mapToSource(index) );
2529     }
2530     return item;
2531 }
2532
2533 QModelIndexList GroupsModel::getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const
2534 {
2535     QModelIndexList elements;
2536     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2537     if ( m != NULL ){
2538         elements = m->getGroupElements( mapToSource(iGroup), kind );
2539     }
2540     return elements;
2541 }
2542
2543 MeshModel::MeshModel( QObject * parent ) :
2544                               QSortFilterProxyModel( parent )
2545 {
2546     QString meshRegExp =QString("(%1|%2|%3|%4)").arg(LAW_TREE).arg(LAW_DIR_TREE)                            .arg(PROPAGATION_TREE).arg(PROPAGATION_DIR_TREE);
2547
2548     setFilterRole( HEXA_TREE_ROLE );
2549     setFilterRegExp ( QRegExp(meshRegExp) );
2550 }
2551
2552 MeshModel::~MeshModel()
2553 {
2554 }
2555
2556 Qt::ItemFlags MeshModel::flags(const QModelIndex &index) const
2557 {
2558     Qt::ItemFlags flags;
2559
2560     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2561     if ( m != NULL ){
2562         flags = m->flags( mapToSource(index) );
2563     }
2564     return flags;
2565 }
2566
2567 QVariant MeshModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2568 {
2569     if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2570         return QVariant( "Mesh" );
2571     } else {
2572         return QSortFilterProxyModel::headerData ( section, orientation, role );
2573     }
2574 }
2575
2576 QStandardItem* MeshModel::itemFromIndex ( const QModelIndex & index ) const
2577 {
2578     QStandardItem *item = NULL;
2579     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2580     if ( m != NULL ){
2581         item = m->itemFromIndex( mapToSource(index) );
2582     }
2583     return item;
2584 }
2585
2586 QModelIndexList MeshModel::getPropagation( const QModelIndex& iPropagation ) const
2587 {
2588     QModelIndexList edges;
2589     DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2590     if ( m != NULL ){
2591         edges = m->getPropagation( mapToSource(iPropagation) );
2592     }
2593     return edges;
2594 }
2595
2596
2597 // ================================== NEW ======================================
2598
2599 // ===== CARTESIAN GRID
2600
2601 QModelIndex DocumentModel::makeCartesianTop(int nx, int ny, int nz)
2602 {
2603     QModelIndex result;
2604
2605     HEXA_NS::Elements* helts = _hexaDocument->makeCartesianTop( nx, ny, nz );
2606     if ( BadElement(helts) )
2607         return result;
2608
2609     result = addElementsToTree(helts, _elementsDirItem);
2610
2611     return result;
2612 }
2613
2614 QModelIndex DocumentModel::makeCartesianUni(const QModelIndex& icenter,
2615                             const QModelIndex& ibase, const QModelIndex& ivec, const QModelIndex& iaxis,
2616                             double lx, double ly, double lz, int nx, int ny, int nz)
2617 {
2618     QModelIndex result;
2619
2620     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2621     HEXA_NS::Vector* hbase   = getHexaPtr<HEXA_NS::Vector*>(ibase);
2622     HEXA_NS::Vector* hvec    = getHexaPtr<HEXA_NS::Vector*>(ivec);
2623     HEXA_NS::Vector* haxis   = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2624
2625     HEXA_NS::Elements* helts = _hexaDocument->makeCartesianUni( hcenter, hbase, hvec, haxis,
2626                                                                 lx, ly, lz, nx, ny, nz);
2627     if ( BadElement(helts) )
2628         return result;
2629
2630     result = addElementsToTree(helts, _elementsDirItem);
2631
2632     return result;
2633 }
2634
2635 QModelIndex DocumentModel::makeCartesian(const QModelIndex& icenter,
2636                                          const QModelIndex& ibase, const QModelIndex& ivec, const QModelIndex& iaxis,
2637                                          vector<double>& radius, vector<double>& angles, vector<double>& heights)
2638 {
2639     QModelIndex result;
2640
2641     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2642     HEXA_NS::Vector* hbase   = getHexaPtr<HEXA_NS::Vector*>(ibase);
2643     HEXA_NS::Vector* hvec    = getHexaPtr<HEXA_NS::Vector*>(ivec);
2644     HEXA_NS::Vector* haxis   = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2645
2646     HEXA_NS::Elements* helts = _hexaDocument->makeCartesian( hcenter, hbase, hvec, haxis,
2647                                                              radius, angles, heights);
2648     if ( BadElement(helts) )
2649         return result;
2650
2651     result = addElementsToTree(helts, _elementsDirItem);
2652
2653     return result;
2654 }
2655
2656
2657 // ===== SPHERE
2658
2659 QModelIndex DocumentModel::makeSphereTop (int nr, int na, int nh)
2660 {
2661     QModelIndex result;
2662
2663     HEXA_NS::Elements* helts = _hexaDocument->makeSphereTop( nr, na, nh );
2664     if ( BadElement(helts) )
2665         return result;
2666
2667     result = addElementsToTree(helts, _elementsDirItem);
2668
2669     return result;
2670 }
2671
2672 QModelIndex DocumentModel::makeSphereUni (QModelIndex& icenter,
2673                                           QModelIndex& ivec_x, QModelIndex& ivec_z,
2674                                           double rtrou, double rext, double ang,
2675                                           QModelIndex& ivplan,
2676                                           int nr, int na, int nh)
2677 {
2678     QModelIndex result;
2679
2680     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2681     HEXA_NS::Vector* hvec_x  = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2682     HEXA_NS::Vector* hvec_z  = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2683     HEXA_NS::Vertex* hvplan  = getHexaPtr<HEXA_NS::Vertex*>(ivplan);
2684
2685     HEXA_NS::Elements* helts = _hexaDocument->makeSphereUni( hcenter, hvec_x, hvec_z,
2686                                                              rtrou, rext, ang, hvplan,
2687                                                              nr, na, nh);
2688     result = addElementsToTree(helts, _elementsDirItem);
2689
2690     return result;
2691 }
2692
2693 QModelIndex DocumentModel::makeSphere    (QModelIndex& icenter,
2694                                           QModelIndex& ivec_x, QModelIndex& ivec_z,
2695                                           vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2696 {
2697     QModelIndex result;
2698
2699     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2700     HEXA_NS::Vector* hvec_x  = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2701     HEXA_NS::Vector* hvec_z  = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2702
2703     HEXA_NS::Elements* helts = _hexaDocument->makeSphere( hcenter, hvec_x, hvec_z,
2704                                                           tray, tang, thaut);
2705
2706     result = addElementsToTree(helts, _elementsDirItem);
2707
2708     return result;
2709 }
2710
2711 // ====== SPHERICAL
2712
2713 QModelIndex DocumentModel::makeSphericalTop (int nbre, int crit)
2714 {
2715     QModelIndex result;
2716
2717     HEXA_NS::Elements* helts = _hexaDocument->makeSphericalTop(nbre, crit);
2718     if (BadElement(helts))
2719         return result;
2720
2721     result = addElementsToTree(helts, _elementsDirItem);
2722
2723     return result;
2724 }
2725
2726 QModelIndex DocumentModel::makeSphericalUni (QModelIndex& icenter,
2727                                              QModelIndex& ivec_x, QModelIndex& ivec_z,
2728                                              double rayon,
2729                                              int nbre, int crit)
2730 {
2731     QModelIndex result;
2732
2733     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2734     HEXA_NS::Vector* hvec_x  = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2735     HEXA_NS::Vector* hvec_z  = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2736
2737     HEXA_NS::Elements* helts = _hexaDocument->makeSphericalUni(hcenter, hvec_x, hvec_z, rayon, nbre, crit);
2738     if (BadElement(helts))
2739         return result;
2740
2741     result = addElementsToTree(helts, _elementsDirItem);
2742
2743     return result;
2744 }
2745
2746 QModelIndex DocumentModel::makeSpherical    (QModelIndex& icenter,
2747                                              QModelIndex& ivec_x, QModelIndex& ivec_z,
2748                                              vector<double>& rayon,
2749                                              int crit)
2750 {
2751     QModelIndex result;
2752
2753     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2754     HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2755     HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2756
2757     HEXA_NS::Elements* helts = _hexaDocument->makeSpherical(hcenter, hvec_x, hvec_z, rayon, crit);
2758     if (BadElement(helts))
2759         return result;
2760
2761     result = addElementsToTree(helts, _elementsDirItem);
2762
2763     return result;
2764 }
2765
2766 // ===== RIND
2767 QModelIndex DocumentModel::makeRindTop (int nr, int na, int nh)
2768 {
2769     QModelIndex result;
2770
2771     HEXA_NS::Elements* helts = _hexaDocument->makeRindTop(nr, na, nh);
2772     if (BadElement(helts))
2773         return result;
2774
2775     result = addElementsToTree(helts, _elementsDirItem);
2776
2777     return result;
2778 }
2779
2780 QModelIndex DocumentModel::makeRindUni (QModelIndex& icenter,
2781                                         QModelIndex& ivec_x, QModelIndex& ivec_z,
2782                                         double raytrou, double rint, double rext, double ang,
2783                                         QModelIndex& ivplan,
2784                                         int nr, int na, int nh)
2785 {
2786     QModelIndex result;
2787
2788     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2789     HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2790     HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2791     HEXA_NS::Vertex* hvplan = getHexaPtr<HEXA_NS::Vertex*>(ivplan);
2792
2793     HEXA_NS::Elements* helts = _hexaDocument->makeRindUni(hcenter, hvec_x, hvec_z, raytrou, rint, rext, ang,
2794                                                           hvplan, nr, na, nh);
2795     if (BadElement(helts))
2796         return result;
2797
2798     result = addElementsToTree(helts, _elementsDirItem);
2799
2800     return result;
2801 }
2802
2803 QModelIndex DocumentModel::makeRind    (QModelIndex& icenter,
2804                                         QModelIndex& ivec_x, QModelIndex& ivec_z,
2805                                         vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2806 {
2807     QModelIndex result;
2808
2809     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2810     HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2811     HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2812
2813     HEXA_NS::Elements* helts = _hexaDocument->makeRind(hcenter, hvec_x, hvec_z, tray, tang, thaut);
2814     if (BadElement(helts))
2815         return result;
2816
2817     result = addElementsToTree(helts, _elementsDirItem);
2818
2819     return result;
2820 }
2821
2822 // ======== Cylinder
2823 QModelIndex DocumentModel::makeCylinderTop(int nr, int na, int nh)
2824 {
2825     QModelIndex result;
2826
2827     HEXA_NS::Elements* helts = _hexaDocument->makeCylinderTop(nr, na, nh);
2828     if (BadElement(helts))
2829         return result;
2830
2831     result = addElementsToTree(helts, _elementsDirItem);
2832
2833     return result;
2834 }
2835
2836 QModelIndex DocumentModel::makeCylinderUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2837                                            double rint, double rext, double angle, double haut,
2838                                            int nr, int na, int nh)
2839 {
2840     QModelIndex result;
2841
2842     HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2843     HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2844     HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2845
2846     HEXA_NS::Elements* helts = _hexaDocument->makeCylinderUni(horig, hvecx, hvecz,
2847                                                               rint, rext, angle, haut,
2848                                                               nr, na, nh);
2849     if (BadElement(helts))
2850         return result;
2851
2852     result = addElementsToTree(helts, _elementsDirItem);
2853
2854     return result;
2855 }
2856
2857 QModelIndex DocumentModel::makeCylinder(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2858                                         vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2859 {
2860     QModelIndex result;
2861
2862     HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2863     HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2864     HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2865
2866     HEXA_NS::Elements* helts = _hexaDocument->makeCylinder(horig, hvecx, hvecz, tray, tang, thaut);
2867     if (BadElement(helts))
2868         return result;
2869
2870     result = addElementsToTree(helts, _elementsDirItem);
2871
2872     return result;
2873 }
2874
2875
2876 // ======== Cylinders
2877 QModelIndex DocumentModel::makeCylinders(QModelIndex& iorig1, QModelIndex& ivecz1,  double r1, double h1,
2878                                          QModelIndex& iorig2, QModelIndex& ivecz2, double r2, double h2)
2879 {
2880     QModelIndex result;
2881
2882     HEXA_NS::Vertex* horig1 = getHexaPtr<HEXA_NS::Vertex*>(iorig1);
2883     HEXA_NS::Vertex* horig2 = getHexaPtr<HEXA_NS::Vertex*>(iorig2);
2884     HEXA_NS::Vector* hvecz1 = getHexaPtr<HEXA_NS::Vector*>(ivecz1);
2885     HEXA_NS::Vector* hvecz2 = getHexaPtr<HEXA_NS::Vector*>(ivecz2);
2886
2887     HEXA_NS::BiCylinder* helts = _hexaDocument->makeCylinders(horig1, hvecz1, r1, h1,
2888                                                               horig2, hvecz2, r2, h2);
2889     if (BadElement(helts))
2890         return result;
2891
2892     result = addElementsToTree(helts, _crossElementsDirItem);
2893
2894     return result;
2895 }
2896
2897 // =========== PIPE
2898 QModelIndex DocumentModel::makePipeTop(int nr, int na, int nh)
2899 {
2900     QModelIndex result;
2901
2902     HEXA_NS::Elements* helts = _hexaDocument->makePipeTop(nr, na, nh);
2903     if (BadElement(helts))
2904         return result;
2905
2906     result = addElementsToTree(helts, _elementsDirItem);
2907
2908     return result;
2909 }
2910
2911 QModelIndex DocumentModel::makePipeUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2912                                        double rint, double rext, double angle, double haut,
2913                                        int nr, int na, int nh)
2914 {
2915     QModelIndex result;
2916
2917     HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2918     HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2919     HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2920
2921     HEXA_NS::Elements* helts = _hexaDocument->makePipeUni(horig, hvecx, hvecz, rint, rext, angle,
2922                                                           haut, nr, na, nh);
2923     if (BadElement(helts))
2924         return result;
2925
2926     result = addElementsToTree(helts, _elementsDirItem);
2927
2928     return result;
2929 }
2930
2931 QModelIndex DocumentModel::makePipe(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2932                                     vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2933 {
2934     QModelIndex result;
2935
2936     HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2937     HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2938     HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2939
2940     HEXA_NS::Elements* helts = _hexaDocument->makePipe(horig, hvecx, hvecz, tray, tang, thaut);
2941     if (BadElement(helts))
2942         return result;
2943
2944     result = addElementsToTree(helts, _elementsDirItem);
2945
2946     return result;
2947 }
2948
2949 // ======== Pipes
2950 QModelIndex DocumentModel::makePipes(QModelIndex& iorig1, QModelIndex& ivecz1, double rint1, double rex1, double h1,
2951                                      QModelIndex& iorig2, QModelIndex& ivecz2, double rint2, double rex2, double h2)
2952 {
2953     QModelIndex result;
2954
2955     HEXA_NS::Vertex* horig1 = getHexaPtr<HEXA_NS::Vertex*>(iorig1);
2956     HEXA_NS::Vertex* horig2 = getHexaPtr<HEXA_NS::Vertex*>(iorig2);
2957     HEXA_NS::Vector* hvecz1 = getHexaPtr<HEXA_NS::Vector*>(ivecz1);
2958     HEXA_NS::Vector* hvecz2 = getHexaPtr<HEXA_NS::Vector*>(ivecz2);
2959
2960     HEXA_NS::BiCylinder* helts = _hexaDocument->makePipes(horig1, hvecz1, rint1, rex1, h1,
2961                                                         horig2, hvecz2, rint2, rex2, h2);
2962     if (BadElement(helts))
2963         return result;
2964
2965     result = addElementsToTree(helts, _crossElementsDirItem);
2966
2967     return result;
2968 }
2969
2970 // ======== Join Quads
2971 QModelIndex DocumentModel::joinQuadUni(QModelIndex&  istart, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
2972                                        QModelIndex& iv3, QModelIndex& iv4, int nb)
2973 {
2974     QModelIndex result;
2975
2976     HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
2977     HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
2978     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
2979     HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
2980     HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
2981     HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
2982
2983     HEXA_NS::Elements* helts = _hexaDocument->joinQuadUni(hstart, hdest, hv1, hv2, hv3, hv4, nb);
2984     if (BadElement(helts))
2985         return result;
2986
2987     result = addElementsToTree(helts, _elementsDirItem);
2988
2989     return result;
2990 }
2991
2992 QModelIndex DocumentModel::joinQuad(QModelIndex&  istart, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
2993                      QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen)
2994 {
2995     QModelIndex result;
2996
2997     HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
2998     HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
2999     HEXA_NS::Vertex* hva1 = getHexaPtr<HEXA_NS::Vertex*>(iva1);
3000     HEXA_NS::Vertex* hvb1 = getHexaPtr<HEXA_NS::Vertex*>(ivb1);
3001     HEXA_NS::Vertex* hva2 = getHexaPtr<HEXA_NS::Vertex*>(iva2);
3002     HEXA_NS::Vertex* hvb2 = getHexaPtr<HEXA_NS::Vertex*>(ivb2);
3003
3004     HEXA_NS::Elements* helts = _hexaDocument->joinQuad(hstart, hdest, hva1, hvb1, hva2, hvb2, tlen);
3005     if (BadElement(helts))
3006         return result;
3007
3008     result = addElementsToTree(helts, _elementsDirItem);
3009
3010     return result;
3011 }
3012
3013 QModelIndex DocumentModel::joinQuadsUni(QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
3014                                         QModelIndex& iv3, QModelIndex& iv4, int nb)
3015 {
3016     QModelIndex result;
3017
3018     HEXA_NS::Quads hstarts;
3019     int nbQuads = istarts.size();
3020     for (int i = 0; i < nbQuads; ++i)
3021         hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3022
3023     HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
3024     HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
3025     HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
3026     HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
3027     HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
3028
3029     HEXA_NS::Elements* helts = _hexaDocument->joinQuadsUni(hstarts, hdest, hv1, hv2, hv3, hv4, nb);
3030     if (BadElement(helts))
3031         return result;
3032
3033     result = addElementsToTree(helts, _elementsDirItem);
3034
3035     return result;
3036 }
3037
3038 QModelIndex DocumentModel::joinQuads(QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
3039                                      QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen)
3040 {
3041     QModelIndex result;
3042
3043     HEXA_NS::Quads hstarts;
3044     int nbQuads = istarts.size();
3045     for (int i = 0; i < nbQuads; ++i)
3046         hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3047
3048     HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
3049     HEXA_NS::Vertex* hva1 = getHexaPtr<HEXA_NS::Vertex*>(iva1);
3050     HEXA_NS::Vertex* hvb1 = getHexaPtr<HEXA_NS::Vertex*>(ivb1);
3051     HEXA_NS::Vertex* hva2 = getHexaPtr<HEXA_NS::Vertex*>(iva2);
3052     HEXA_NS::Vertex* hvb2 = getHexaPtr<HEXA_NS::Vertex*>(ivb2);
3053
3054     HEXA_NS::Elements* helts = _hexaDocument->joinQuads(hstarts, hdest, hva1, hvb1, hva2, hvb2, tlen);
3055     if (BadElement(helts))
3056         return result;
3057
3058     result = addElementsToTree(helts, _elementsDirItem);
3059
3060     return result;
3061 }
3062
3063 // ======== Quad Revolution
3064 QModelIndex DocumentModel::revolutionQuadUni(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
3065                                              double angle, int nbre)
3066 {
3067     QModelIndex result;
3068
3069     HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3070     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
3071     HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3072
3073     HEXA_NS::Elements* helts = _hexaDocument->revolutionQuadUni(hstart, hcenter, haxis, angle, nbre);
3074     if (BadElement(helts))
3075         return result;
3076
3077     result = addElementsToTree(helts, _elementsDirItem);
3078
3079     return result;
3080 }
3081
3082 QModelIndex DocumentModel::revolutionQuad(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
3083                                           vector<double>& angles)
3084 {
3085     QModelIndex result;
3086
3087     HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3088     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
3089     HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3090
3091     HEXA_NS::Elements* helts = _hexaDocument->revolutionQuad(hstart, hcenter, haxis, angles);
3092     if (BadElement(helts))
3093         return result;
3094
3095     result = addElementsToTree(helts, _elementsDirItem);
3096
3097     return result;
3098 }
3099
3100 QModelIndex DocumentModel::revolutionQuadsUni(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
3101                                               double angle, int nbre)
3102 {
3103     QModelIndex result;
3104
3105     HEXA_NS::Quads hstarts;
3106     int nbQuads = istarts.count();
3107     for (int i = 0; i < nbQuads; ++i)
3108         hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3109
3110     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
3111     HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3112
3113     HEXA_NS::Elements* helts = _hexaDocument->revolutionQuadsUni(hstarts, hcenter, haxis, angle, nbre);
3114     if (BadElement(helts))
3115         return result;
3116
3117     result = addElementsToTree(helts, _elementsDirItem);
3118
3119     return result;
3120 }
3121
3122 QModelIndex DocumentModel::revolutionQuads(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
3123                                            vector<double>& angles)
3124 {
3125     QModelIndex result;
3126
3127     HEXA_NS::Quads hstarts;
3128     int nbQuads = istarts.count();
3129     for (int i = 0; i < nbQuads; ++i)
3130         hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3131
3132     HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
3133     HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3134
3135     HEXA_NS::Elements* helts = _hexaDocument->revolutionQuads(hstarts, hcenter, haxis, angles);
3136     if (BadElement(helts))
3137         return result;
3138
3139     result = addElementsToTree(helts, _elementsDirItem);
3140
3141     return result;
3142
3143 }
3144
3145 // ==== PrismQuad or ExtrudeQuad
3146 QModelIndex DocumentModel::extrudeQuadTop(QModelIndex& istart, int nbre)
3147 {
3148     QModelIndex result;
3149
3150     HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3151     HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadTop(hstart, nbre);
3152     if (BadElement(helts))
3153         return result;
3154
3155     result = addElementsToTree(helts, _elementsDirItem);
3156
3157     return result;
3158 }
3159
3160 QModelIndex DocumentModel::extrudeQuadUni(QModelIndex& istart, QModelIndex& dv, double len, int nbre)
3161 {
3162     QModelIndex result;
3163
3164     HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3165     HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(dv);
3166
3167     HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadUni(hstart, hvec, len, nbre);
3168     if (BadElement(helts))
3169         return result;
3170
3171     result = addElementsToTree(helts, _elementsDirItem);
3172
3173     return result;
3174 }
3175
3176 QModelIndex DocumentModel::extrudeQuad(QModelIndex& istart, QModelIndex& dv, vector<double>& tlen)
3177 {
3178     QModelIndex result;
3179
3180     HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3181     HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(dv);
3182
3183     HEXA_NS::Elements* helts = _hexaDocument->extrudeQuad(hstart, hvec, tlen);
3184     if (BadElement(helts))
3185         return result;
3186     result = addElementsToTree(helts, _elementsDirItem);
3187
3188     return result;
3189 }
3190
3191 QModelIndex DocumentModel::extrudeQuadsTop (QModelIndexList& istarts, int nbre)
3192 {
3193     QModelIndex result;
3194
3195     HEXA_NS::Quads hquads;
3196     int nbQuads = istarts.count();
3197     for (int i = 0; i < nbQuads; ++i)
3198         hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3199
3200     HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadsTop(hquads, nbre);
3201     if (BadElement(helts))
3202         return result;
3203     result = addElementsToTree(helts, _elementsDirItem);
3204
3205     return result;
3206 }
3207
3208 QModelIndex DocumentModel::extrudeQuadsUni (QModelIndexList& istarts, QModelIndex& axis, double len, int nbre)
3209 {
3210     QModelIndex result;
3211
3212     HEXA_NS::Quads hquads;
3213     int nbQuads = istarts.count();
3214     for (int i = 0; i < nbQuads; ++i)
3215         hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3216
3217     HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(axis);
3218
3219     HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadsUni(hquads, haxis, len, nbre);
3220     if (BadElement(helts))
3221         return result;
3222     result = addElementsToTree(helts, _elementsDirItem);
3223
3224     return result;
3225 }
3226
3227 QModelIndex DocumentModel::extrudeQuads(QModelIndexList& istarts, QModelIndex& iaxis, vector<double>& tlen)
3228 {
3229     QModelIndex result;
3230
3231     HEXA_NS::Quads hquads;
3232     int nbQuads = istarts.count();
3233     for (int i=0; i < nbQuads; ++i)
3234         hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3235
3236     HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3237
3238     HEXA_NS::Elements* helts = _hexaDocument->extrudeQuads(hquads, haxis, tlen);
3239     if (BadElement(helts))
3240         return result;
3241     result = addElementsToTree(helts, _elementsDirItem);
3242
3243     return result;
3244 }
3245
3246 // ==== Cut Edge
3247 QModelIndex DocumentModel::cutUni(QModelIndex& iEdge, int nbre)
3248 {
3249     QModelIndex result;
3250
3251     HEXA_NS::Edge* hedge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
3252
3253     HEXA_NS::Elements* helts = _hexaDocument->cutUni(hedge, nbre);
3254     if (BadElement(helts))
3255         return result;
3256     result = addElementsToTree(helts, _elementsDirItem);
3257
3258     return result;
3259 }
3260
3261 QModelIndex DocumentModel::cut(QModelIndex& iEdge, vector<double>& tlen)
3262 {
3263     QModelIndex result;
3264
3265     HEXA_NS::Edge* hedge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
3266
3267     HEXA_NS::Elements* helts = _hexaDocument->cut(hedge, tlen);
3268     if (BadElement(helts))
3269         return result;
3270     result = addElementsToTree(helts, _elementsDirItem);
3271
3272     return result;
3273 }
3274
3275 // ================================== END NEW ==================================