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