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