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