1 // Copyright (C) 2009-2013 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 //CS_TODO: relever les fonctions qui nécessitent updateData().
21 // addGroupElement à tester
25 #include "utilities.h"
27 #include "HEXABLOCKGUI_DocumentModel.hxx"
28 #include "HEXABLOCKGUI_DocumentItem.hxx"
30 #include "HEXABLOCKGUI.hxx"
31 #include "HEXABLOCKGUI_Trace.hxx"
33 #include "HexVertex.hxx"
34 #include "HexShape.hxx"
35 #include "HexSubShape.hxx"
36 #include "HexAssoEdge.hxx"
37 #include "HexBiCylinder.hxx"
40 #include <BRepBuilderAPI_MakeVertex.hxx>
42 #include "HEXABLOCKGUI_SalomeTools.hxx"
44 #include <SALOME_ListIO.hxx>
45 #include <SALOMEconfig.h>
46 #include <SUIT_ViewWindow.h>
50 #include "HEXABLOCKGUI_VtkDocumentGraphicView.hxx"
57 //using namespace HEXA_NS;
58 using namespace HEXABLOCK::GUI;
60 /*****************************************************************
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 ),
69 // _hexaDocument( new HEXA_NS::Document("/tmp/doc.hex") ), //CS_TODO
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")) ),
76 _vectorDirItem( new QStandardItem(tr("TREE_ITEM_VECTOR")) ),
77 _elementsDirItem( new QStandardItem(tr("TREE_ITEM_ELEMENT")) ),
78 _crossElementsDirItem( new QStandardItem(tr("TREE_ITEM_CROSSELEMENT")) ),
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")) ),
84 _groupDirItem( new QStandardItem(tr("TREE_ITEM_GROUP")) ),
86 _lawDirItem( new QStandardItem(tr("TREE_ITEM_LAW")) ),
87 _propagationDirItem( new QStandardItem(tr("TREE_ITEM_PROPAGATION")) ),
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 ),
97 _disallowEdition( false )
99 // setColumnCount( 4 ); //CS_TEST
100 if ( !_hexaDocument && _hexaFile->open() ){
101 _hexaDocument = new HEXA_NS::Document( _hexaFile->fileName().toLatin1() );
102 _hexaDocument->reorderFaces();
105 QStandardItem *parentItem = invisibleRootItem();
106 // parentItem->setData( QString::number( reinterpret_cast<intptr_t>(_hexaDocument) ), HEXA_ENTRY_ROLE );
107 parentItem->setData( _entry, HEXA_ENTRY_ROLE );
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 );
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 );
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 );
122 _groupDirItem->setData( GROUP_DIR_TREE, HEXA_TREE_ROLE );
124 //CS_TODO associations
126 _lawDirItem->setData( LAW_DIR_TREE, HEXA_TREE_ROLE );
127 _propagationDirItem->setData( PROPAGATION_DIR_TREE, HEXA_TREE_ROLE );
129 parentItem->appendRow(_vertexDirItem);
130 parentItem->appendRow(_edgeDirItem);
131 parentItem->appendRow(_quadDirItem);
132 parentItem->appendRow(_hexaDirItem);
134 parentItem->appendRow(_vectorDirItem);
135 parentItem->appendRow(_elementsDirItem);
136 parentItem->appendRow(_crossElementsDirItem);
138 parentItem->appendRow(_explicitShapesDirItem);
139 parentItem->appendRow(_implicitShapesDirItem);
141 parentItem->appendRow(_groupDirItem);
142 parentItem->appendRow(_lawDirItem);
143 parentItem->appendRow(_propagationDirItem);
146 DocumentModel::~DocumentModel()
148 if (_hexaDocument != NULL)
149 delete _hexaDocument;
151 if (_hexaFile != NULL)
155 void DocumentModel::setName(const QString& name)
157 _hexaDocument->setName( name.toLocal8Bit().constData() );
158 emit nameChanged(QString(_hexaDocument->getName()));
161 HEXA_NS::EltBase* DocumentModel::getHexaPtr(const QModelIndex& iElt)
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;
180 //get the number of elements of type 'eltType' in the document
181 int DocumentModel::getNbrElt(HEXA_NS::EnumElt eltType)
183 if (_hexaDocument == NULL) return 0;
185 return _hexaDocument->getNbrElt(eltType);
188 //get the number of elements of type 'eltType' used in the document
189 int DocumentModel::getNbrUsedElt(HEXA_NS::EnumElt eltType)
191 if (_hexaDocument == NULL) return 0;
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();
206 //associate a shape to the current document
207 bool DocumentModel::addShape(TopoDS_Shape& aShape, QString& name, bool publish)
209 if (aShape.IsNull() || name.isEmpty())
211 bool ok = (_hexaDocument != NULL ? _hexaDocument->addShape(aShape, name.toStdString().c_str()) != NULL : false);
213 // * publish the shape in the study
216 HEXABLOCKGUI* module = HEXABLOCKGUI::getInstance();
219 QMap<QString, TopoDS_Shape> topo_shapes;
220 topo_shapes[name] = aShape;
221 module->addInStudy(topo_shapes, docShapesEntry, docShapesName);
232 //get the number of unused elements of type 'eltType' in the document
233 int DocumentModel::getNbrUnusedElt(HEXA_NS::EnumElt eltType)
235 if (_hexaDocument == NULL)
238 return getNbrElt(eltType) - getNbrUsedElt(eltType);
242 //Load the current Document
243 void DocumentModel::load()
245 if (_hexaDocument == NULL)
248 load(_hexaDocument->getName());
252 void DocumentModel::load( const QString& xmlFileName ) // Fill Data
254 _hexaDocument->loadXml(xmlFileName.toLocal8Bit().constData() );
264 emit patternDataChanged();
267 bool DocumentModel::isEmpty() const
269 if (_hexaDocument == NULL) return true;
270 return _hexaDocument->isEmpty();
273 void DocumentModel::save( const QString& xmlFileName )
275 _hexaDocument->save( xmlFileName.toLocal8Bit().constData() );
278 QString DocumentModel::getName()
280 return _hexaDocument->getName();
283 void DocumentModel::updateData()
289 emit patternDataChanged();
292 void DocumentModel::updateGeomTree()
298 QModelIndex DocumentModel::addElementsToTree(HEXA_NS::Elements* helts, QStandardItem* tree)
300 QModelIndex eltIndex;
301 if (helts == NULL || tree == NULL)
305 ElementsItem* eltsItem = new ElementsItem(helts);
306 tree->appendRow(eltsItem);
308 return eltsItem->index();
311 void DocumentModel::refresh()
322 emit patternDataChanged();
325 void DocumentModel::clearAll()
335 void DocumentModel::clearData()
337 _vertexDirItem->removeRows( 0, _vertexDirItem->rowCount() );
338 _edgeDirItem->removeRows(0, _edgeDirItem->rowCount() );
339 _quadDirItem->removeRows(0, _quadDirItem->rowCount() );
340 _hexaDirItem->removeRows(0, _hexaDirItem->rowCount() );
344 void DocumentModel::clearBuilder()
346 _vectorDirItem->removeRows(0, _vectorDirItem->rowCount() );
347 _elementsDirItem->removeRows(0, _elementsDirItem->rowCount() );
348 _crossElementsDirItem->removeRows(0, _crossElementsDirItem->rowCount() );
351 void DocumentModel::clearGeometry()
353 _explicitShapesDirItem->removeRows(0, _explicitShapesDirItem->rowCount() );
354 _implicitShapesDirItem->removeRows(0, _implicitShapesDirItem->rowCount() );
355 _cloudOfPointsDirItem->removeRows(0, _cloudOfPointsDirItem->rowCount() );
358 void DocumentModel::clearAssociation()
363 void DocumentModel::clearGroups()
365 _groupDirItem->removeRows(0, _groupDirItem->rowCount() );
368 void DocumentModel::clearMesh()
370 _lawDirItem->removeRows(0, _lawDirItem->rowCount() );
371 _propagationDirItem->removeRows(0, _propagationDirItem->rowCount() );
375 void DocumentModel::fillData()
377 PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
380 pdsm->clearHighlightedItems();
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);
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);
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);
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);
421 void DocumentModel::fillBuilder()
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);
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? ******/
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);
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);
462 //********************************************************************************************************
465 void DocumentModel::fillGeometry()
467 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
468 if (_hexaDocument == NULL || isEmpty() || pgsm == NULL)
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;
478 // * fill the shape tree
481 pgsm->clearHighlightedItems();
482 QMap<QString, TopoDS_Shape> topo_shapes;
483 int nbShapes = _hexaDocument->countShape();
484 for (int i=0; i < nbShapes; ++i)
486 shape = _hexaDocument->getShape(i);
487 QString shapeName = shape->getName();
488 if (!docShapesEntry.contains(shapeName))
490 if (shape->getOrigin() == HEXA_NS::SH_CLOUD)
492 compoundBuilder.MakeCompound(vertexCompound);
493 topo_shapes[shapeName] = vertexCompound;
496 topo_shapes[shapeName] = shape->getShape();
499 GeomShapeItem* shItem = new GeomShapeItem(shape);
500 if (shape->getOrigin() == HEXA_NS::SH_IMPORT)
502 _explicitShapesDirItem->appendRow(shItem);
505 _implicitShapesDirItem->appendRow(shItem);
507 //add vertices to the tree
508 QStandardItem* geomPointDirItem = NULL;
509 if (shape->getOrigin() != HEXA_NS::SH_CLOUD)
511 geomPointDirItem = new QStandardItem(tr("TREE_ITEM_VERTEX"));
512 geomPointDirItem->setData( GEOMPOINT_DIR_TREE, HEXA_TREE_ROLE );
514 if (geomPointDirItem != NULL)
515 shItem->appendRow(geomPointDirItem);
516 int nbVertexShape = shape->countVertex();
517 for (int j=0; j < nbVertexShape; ++j)
519 node = shape->getVertexShape(j);
520 GeomPointItem* gPointItem = new GeomPointItem(node);
521 if (geomPointDirItem != NULL)
522 geomPointDirItem->appendRow(gPointItem);
524 shItem->appendRow(gPointItem);
525 shapeById[shapeName+","+QString::number(node->getIdent())] = node;
527 // * update the compound of vertices
528 if (shape->getOrigin() == HEXA_NS::SH_CLOUD && !vertexCompound.IsNull())
529 compoundBuilder.Add(topo_shapes[shapeName], node->getShape());
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
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)
542 line = shape->getEdgeShape(j);
543 GeomEdgeItem* gEdgeItem = new GeomEdgeItem(line);
544 geomEdgeDirItem->appendRow(gEdgeItem);
545 shapeById[shapeName+","+QString::number(line->getIdent())] = line;
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)
555 face = shape->getFaceShape(j);
556 GeomFaceItem* gFaceItem = new GeomFaceItem(face);
557 geomFaceDirItem->appendRow(gFaceItem);
558 shapeById[shapeName+","+QString::number(face->getIdent())] = face;
562 if (topo_shapes.size() == 0)
566 HEXABLOCKGUI* module = HEXABLOCKGUI::getInstance();
568 module->addInStudy(topo_shapes, docShapesEntry, docShapesName);
571 void DocumentModel::fillAssociation()
575 //------------------------------------------- NEW ITEMS
576 //void DocumentModel::fillGroups()
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);
588 //void DocumentModel::fillMesh()
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);
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);
609 //----------------------------------------------- END NEW ITEMS
611 void DocumentModel::fillGroups()
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);
625 void DocumentModel::fillMesh()
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);
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);
650 HEXA_NS::Hexa* DocumentModel::getQuadHexa(HEXA_NS::Quad* quad)
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;
662 Qt::ItemFlags DocumentModel::flags(const QModelIndex &index) const
666 if (!index.isValid()) return Qt::ItemIsEnabled;
668 if ( _disallowEdition ){
669 return QAbstractItemModel::flags(index) | Qt::ItemFlags( ~Qt::ItemIsEditable );
671 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
675 void DocumentModel::allowEdition()
677 _disallowEdition = false;
680 void DocumentModel::disallowEdition()
682 _disallowEdition = true;
685 void DocumentModel::allowDataSelectionOnly()
687 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
688 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
689 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
690 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
692 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
693 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
694 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
696 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
697 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
698 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
701 void DocumentModel::allowVertexSelectionOnly()
703 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable);
704 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
705 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
706 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
708 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
709 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
710 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
712 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
713 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
714 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
716 // emit layoutChanged();
719 void DocumentModel::allowEdgeSelectionOnly()
721 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
722 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
723 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
724 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
726 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
727 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
728 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
730 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
731 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
732 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
735 void DocumentModel::allowQuadSelectionOnly()
737 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
738 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
739 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
740 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
742 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
743 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
744 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
746 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
747 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
748 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
751 void DocumentModel::allowHexaSelectionOnly()
753 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
754 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
755 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
756 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
758 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
759 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
760 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
762 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
763 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
764 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
767 void DocumentModel::allowVectorSelectionOnly()
769 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
770 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
771 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
772 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
774 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
775 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
776 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
778 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
779 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
780 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
783 void DocumentModel::allowCylinderSelectionOnly()
785 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
786 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
787 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
788 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
790 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
791 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
792 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
794 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
795 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
796 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
799 void DocumentModel::allowPipeSelectionOnly()
801 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
802 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
803 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
804 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
806 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
807 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
808 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
810 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
811 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
812 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
815 void DocumentModel::allowElementsSelectionOnly()
817 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
818 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
819 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
820 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
822 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
823 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
824 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
826 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
827 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
828 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
831 void DocumentModel::allowCrossElementsSelectionOnly()
833 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
834 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
835 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
836 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
838 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
839 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
840 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
842 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
843 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
844 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
847 void DocumentModel::allowLawSelectionOnly()
849 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
850 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
851 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
852 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
854 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
855 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
856 _crossElementsItemFlags = Qt::ItemFlags( Qt::ItemIsEnabled );
858 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
859 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
860 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
864 void DocumentModel::setName( const QModelIndex& iElt, const QString& name )
866 HEXA_NS::EltBase *elt = NULL;
868 switch ( data(iElt, HEXA_TREE_ROLE).toInt() ){
871 HEXA_NS::Group* grp = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Group* >();
872 grp->setName( name.toLatin1().data() );
877 HEXA_NS::Law* l = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Law* >();
878 l->setName( name.toLatin1().data() );
881 // case PROPAGATION_TREE : elt = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Propagation* >(); break;
882 default: elt = getHexaPtr(iElt);
885 if ( elt != NULL ) elt->setName( name.toStdString() );
886 setData( iElt, name );
890 bool DocumentModel::clearEltAssociations( const QModelIndex& iElt )
893 HEXA_NS::EltBase *elt = getHexaPtr(iElt);
896 elt->clearAssociation();
897 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
904 void DocumentModel::clearAssociation(HEXA_NS::EnumElt& eltType)
906 if (_hexaDocument != NULL)
907 _hexaDocument->clearAssociation(eltType);
910 HEXA_NS::Vertex* vertex;
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;
920 //update associations in the model
921 if (eltType == HEXA_NS::EL_VERTEX)
923 nbElts = _hexaDocument->countVertex();
924 for (int i = 0; i < nbElts; ++i)
926 vertex = _hexaDocument->getVertex(i);
927 iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(vertex)));
929 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
932 else if (eltType == HEXA_NS::EL_EDGE)
934 nbElts = _hexaDocument->countEdge();
935 for (int i = 0; i < nbElts; ++i)
937 edge = _hexaDocument->getEdge(i);
938 iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(edge)));
940 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
943 else if (eltType == HEXA_NS::EL_QUAD)
945 nbElts = _hexaDocument->countQuad();
946 for (int i = 0; i < nbElts; ++i)
948 quad = _hexaDocument->getQuad(i);
949 iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(quad)));
951 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
957 QModelIndex DocumentModel::addVertex( double x, double y, double z )
959 QModelIndex vertexIndex;
961 HEXA_NS::Vertex* hv = _hexaDocument->addVertex(x, y, z);
962 if (BadElement(hv)) return vertexIndex;
964 VertexItem* v = new VertexItem(hv, _entry);
965 _vertexDirItem->appendRow(v);
966 vertexIndex = v->index();
967 emit patternDataChanged();
972 QModelIndex DocumentModel::addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 )
974 QModelIndex edgeIndex;
976 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(i_v0);
977 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(i_v1);
979 HEXA_NS::Edge* he = _hexaDocument->addEdge( hv0, hv1 );
980 if ( BadElement(he) ) return edgeIndex;
982 EdgeItem* e = new EdgeItem(he, _entry);
983 _edgeDirItem->appendRow(e);
984 edgeIndex = e->index();
985 emit patternDataChanged();
990 QModelIndex DocumentModel::addEdgeVector ( const QModelIndex &i_v, const QModelIndex &i_vec )
992 QModelIndex edgeIndex;
994 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(i_v);
995 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(i_vec);
997 HEXA_NS::Edge* he = _hexaDocument->addEdgeVector( hv0, hvec );
998 if ( BadElement(he) ) return edgeIndex;
1000 EdgeItem* e = new EdgeItem(he, _entry);
1001 _vectorDirItem->appendRow(e);
1002 edgeIndex = e->index();
1003 emit patternDataChanged();
1008 QModelIndex DocumentModel::addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
1009 const QModelIndex &i_v2, const QModelIndex &i_v3 )
1010 { //CS_TODO : gestion erreur
1011 QModelIndex quadIndex;
1013 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(i_v0);
1014 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(i_v1);
1015 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(i_v2);
1016 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(i_v3);
1018 if ( hv0 && hv1 && hv2 && hv3 ){
1019 HEXA_NS::Quad* hq = _hexaDocument->addQuadVertices( hv0, hv1, hv2, hv3 );
1020 if ( BadElement(hq) ) return quadIndex;
1022 QuadItem* q = new QuadItem(hq, _entry);
1023 _quadDirItem->appendRow(q);
1024 quadIndex = q->index();
1025 emit patternDataChanged();
1031 QModelIndex DocumentModel::addQuadEdges( const QModelIndex &e0, const QModelIndex &e1,
1032 const QModelIndex &e2, const QModelIndex &e3 )
1034 QModelIndex quadIndex;
1036 HEXA_NS::Edge* he0 = getHexaPtr<HEXA_NS::Edge*>(e0);
1037 HEXA_NS::Edge* he1 = getHexaPtr<HEXA_NS::Edge*>(e1);
1038 HEXA_NS::Edge* he2 = getHexaPtr<HEXA_NS::Edge*>(e2);
1039 HEXA_NS::Edge* he3 = getHexaPtr<HEXA_NS::Edge*>(e3);
1041 if ( he0 && he1 && he2 && he3 ){
1043 HEXA_NS::Quad* hq = _hexaDocument->addQuad( he0, he1, he2, he3 );
1044 if ( BadElement(hq) ) return quadIndex;
1046 QuadItem* q = new QuadItem(hq, _entry);
1047 _quadDirItem->appendRow(q);
1048 quadIndex = q->index();
1049 emit patternDataChanged();
1055 QModelIndex DocumentModel::addHexaVertices(
1056 const QModelIndex &iv0, const QModelIndex &iv1,
1057 const QModelIndex &iv2, const QModelIndex &iv3,
1058 const QModelIndex &iv4, const QModelIndex &iv5,
1059 const QModelIndex &iv6, const QModelIndex &iv7 )
1063 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1064 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1065 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
1066 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
1067 HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
1068 HEXA_NS::Vertex* hv5 = getHexaPtr<HEXA_NS::Vertex*>(iv5);
1069 HEXA_NS::Vertex* hv6 = getHexaPtr<HEXA_NS::Vertex*>(iv6);
1070 HEXA_NS::Vertex* hv7 = getHexaPtr<HEXA_NS::Vertex*>(iv7);
1072 HEXA_NS::Hexa* hh = _hexaDocument->addHexaVertices( hv0, hv1, hv2, hv3,
1073 hv4, hv5, hv6, hv7 );
1075 if ( BadElement(hh) ) return iHexa;
1077 HexaItem* h = new HexaItem(hh, _entry);
1078 _hexaDirItem->appendRow(h);
1080 emit patternDataChanged();
1085 QModelIndex DocumentModel::addHexaQuad( const QModelIndex &i_q0, const QModelIndex &i_q1,
1086 const QModelIndex &i_q2,const QModelIndex &i_q3, const QModelIndex &i_q4, const QModelIndex &i_q5 )
1087 { //CS_TODO : gestion erreur
1088 QModelIndex hexaIndex;
1090 HEXA_NS::Quad* hq0 = getHexaPtr<HEXA_NS::Quad*>(i_q0);
1091 HEXA_NS::Quad* hq1 = getHexaPtr<HEXA_NS::Quad*>(i_q1);
1092 HEXA_NS::Quad* hq2 = getHexaPtr<HEXA_NS::Quad*>(i_q2);
1093 HEXA_NS::Quad* hq3 = getHexaPtr<HEXA_NS::Quad*>(i_q3);
1094 HEXA_NS::Quad* hq4 = getHexaPtr<HEXA_NS::Quad*>(i_q4);
1095 HEXA_NS::Quad* hq5 = getHexaPtr<HEXA_NS::Quad*>(i_q5);
1097 HEXA_NS::Hexa* hh = _hexaDocument->addHexa( hq0, hq1, hq2, hq3, hq4, hq5 );
1098 if ( BadElement(hh) ) return hexaIndex;
1100 HexaItem* h = new HexaItem(hh, _entry);
1101 _hexaDirItem->appendRow(h);
1102 hexaIndex = h->index();
1103 emit patternDataChanged();
1108 QModelIndex DocumentModel::addHexaQuads( const QModelIndexList &iquads)
1110 QModelIndex hexaIndex;
1112 HEXA_NS::Hexa* hh = NULL;
1113 HEXA_NS::Quad* hq0, *hq1, *hq2, *hq3, *hq4, *hq5 = NULL;
1115 hq0 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(0));
1116 hq1 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(1));
1117 hq2 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(2));
1118 hq3 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(3));
1119 hq4 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(4));
1120 hq5 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(5));
1122 if ( hq0 && hq1 && hq2 && hq3 && hq4 && hq5 )
1123 hh = _hexaDocument->addHexa( hq0, hq1, hq2, hq3, hq4, hq5 );
1124 else if ( hq0 && hq1 && hq2 && hq3 && hq4 )
1125 hh = _hexaDocument->addHexa5Quads( hq0, hq1, hq2, hq3, hq4 );
1126 else if ( hq0 && hq1 && hq2 && hq3 )
1127 hh = _hexaDocument->addHexa4Quads( hq0, hq1, hq2, hq3 );
1128 else if ( hq0 && hq1 && hq2)
1129 hh = _hexaDocument->addHexa3Quads( hq0, hq1, hq2 );
1130 else if ( hq0 && hq1 )
1131 hh = _hexaDocument->addHexa2Quads( hq0, hq1);
1133 if ( BadElement(hh) ) return hexaIndex;
1136 unsigned int nbRows = _hexaDirItem->rowCount();
1138 hexaIndex = _hexaDirItem->child(nbRows-1)->index();
1143 QModelIndex DocumentModel::addVector( double dx, double dy, double dz )
1145 QModelIndex vectorIndex;
1147 HEXA_NS::Vector* hv = _hexaDocument->addVector(dx, dy, dz);
1148 if ( BadElement(hv) ) return vectorIndex; //Invalid index
1150 VectorItem* v = new VectorItem(hv);
1151 _vectorDirItem->appendRow(v);
1152 vectorIndex = v->index();
1157 QModelIndex DocumentModel::addVectorVertices( const QModelIndex &iv0, const QModelIndex &iv1 )
1161 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1162 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1164 HEXA_NS::Vector* hvec = _hexaDocument->addVectorVertices( hv0, hv1 );
1165 if ( BadElement(hvec) ) return iVec;
1167 VectorItem* vec = new VectorItem(hvec);
1168 _vectorDirItem->appendRow(vec);
1169 iVec = vec->index();
1175 // ************ EDIT HEXABLOCK MODEL ************
1177 bool DocumentModel::updateVertex( const QModelIndex& ivertex, double x, double y, double z )
1181 HEXA_NS::Vertex* hVertex = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1184 // hVertex->setName( name.toStdString() );
1185 hVertex->setX ( x );
1186 hVertex->setY ( y );
1187 hVertex->setZ ( z );
1188 emit patternDataChanged();
1195 bool DocumentModel::removeHexa( const QModelIndex& ihexa )
1197 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1199 int r = _hexaDocument->removeHexa( hHexa );
1208 bool DocumentModel::removeConnectedHexa( const QModelIndex& ihexa )
1210 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1212 int r = _hexaDocument->removeConnectedHexa( hHexa );
1221 bool DocumentModel::mergeVertices( const QModelIndex &iv0, const QModelIndex &iv1 ) //CS_TODO : impact sur le model?
1223 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1224 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1226 int r = _hexaDocument->mergeVertices( hv0, hv1 );
1228 updateData(); //CS_TODO more or less?
1235 bool DocumentModel::mergeEdges( const QModelIndex &ie0, const QModelIndex &ie1,
1236 const QModelIndex &iv0, const QModelIndex &iv1 )
1237 //CS_TODO : impact sur le model?
1239 HEXA_NS::Edge* he0 = getHexaPtr<HEXA_NS::Edge*>(ie0);
1240 HEXA_NS::Edge* he1 = getHexaPtr<HEXA_NS::Edge*>(ie1);
1242 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1243 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1246 int r = _hexaDocument->mergeEdges( he0, he1, hv0, hv1 );
1255 bool DocumentModel::mergeQuads( const QModelIndex& iquad0, const QModelIndex& iquad1,
1256 const QModelIndex& iv0, const QModelIndex& iv1,
1257 const QModelIndex& iv2, const QModelIndex& iv3 )
1259 HEXA_NS::Quad* hquad0 = data(iquad0, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1260 HEXA_NS::Quad* hquad1 = data(iquad1, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1262 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1263 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1264 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
1265 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
1267 int r = _hexaDocument->mergeQuads( hquad0, hquad1, hv0, hv1, hv2, hv3 );
1277 QModelIndex DocumentModel::disconnectVertex( const QModelIndex& ihexa, const QModelIndex& ivertex )
1281 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1282 HEXA_NS::Vertex* hVertex = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1284 HEXA_NS::Elements* hElts = _hexaDocument->disconnectVertex( hHexa, hVertex );
1285 if ( BadElement(hElts) ) return iElts;
1287 updateData(); //CS_TO_CHECK
1288 ElementsItem* elts = new ElementsItem(hElts);
1289 _elementsDirItem->appendRow(elts);
1290 iElts = elts->index();
1295 QModelIndex DocumentModel::disconnectEdge( const QModelIndex& ihexa, const QModelIndex& iedge )
1299 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1300 HEXA_NS::Edge* hEdge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1302 HEXA_NS::Elements* hElts = _hexaDocument->disconnectEdge( hHexa, hEdge );
1303 if ( BadElement(hElts) ) return iElts;
1305 updateData(); //CS_TO_CHECK
1306 ElementsItem* elts = new ElementsItem(hElts);
1307 _elementsDirItem->appendRow(elts);
1308 iElts = elts->index();
1314 QModelIndex DocumentModel::disconnectEdges( const QModelIndexList& ihexas, const QModelIndexList& iedges )
1318 HEXA_NS::Hexas hHexas;
1319 HEXA_NS::Edges hEdges;
1322 HEXA_NS::Edge* hedge = NULL;
1323 foreach( const QModelIndex& iedge, iedges ){
1324 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1325 hEdges.push_back( hedge );
1329 HEXA_NS::Hexa* hhexa = NULL;
1330 foreach( const QModelIndex& ihexa, ihexas ){
1331 hhexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1332 hHexas.push_back( hhexa );
1336 HEXA_NS::Elements* hElts = _hexaDocument->disconnectEdges( hHexas, hEdges );
1337 if ( BadElement(hElts) ) return iElts;
1339 updateData(); //CS_TO_CHECK
1340 ElementsItem* elts = new ElementsItem(hElts);
1341 _elementsDirItem->appendRow(elts);
1342 iElts = elts->index();
1348 QModelIndex DocumentModel::disconnectQuad( const QModelIndex& ihexa, const QModelIndex& iquad )
1352 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1353 HEXA_NS::Quad* hQuad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1355 HEXA_NS::Elements* hElts = _hexaDocument->disconnectQuad( hHexa, hQuad );
1356 if ( BadElement(hElts) ) return iElts;
1358 updateData(); //CS_TO_CHECK
1359 ElementsItem* elts = new ElementsItem(hElts);
1360 _elementsDirItem->appendRow(elts);
1361 iElts = elts->index();
1367 QModelIndex DocumentModel::makeTranslation( const QModelIndex& ielts, const QModelIndex& ivec )
1371 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1372 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1374 HEXA_NS::Elements* hNewElts = _hexaDocument->makeTranslation( hElts, hVec );
1375 if ( BadElement(hNewElts) ) return iElts;
1377 updateData(); //CS_TODO more or less?
1378 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1379 _elementsDirItem->appendRow(eltsItem);
1380 iElts = eltsItem->index();
1387 QModelIndex DocumentModel::makeScale( const QModelIndex& ielts, const QModelIndex& ivex, double k )
1391 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1392 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1394 HEXA_NS::Elements* hNewElts = _hexaDocument->makeScale( hElts, hVex, k );
1395 if ( BadElement(hNewElts) ) return iElts;
1397 updateData(); //CS_TODO more or less?
1398 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1399 _elementsDirItem->appendRow(eltsItem);
1400 iElts = eltsItem->index();
1407 QModelIndex DocumentModel::makeRotation( const QModelIndex& ielts,
1408 const QModelIndex& iv,
1409 const QModelIndex& ivec, double angle )
1413 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1414 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1415 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1417 HEXA_NS::Elements* hNewElts = _hexaDocument->makeRotation( hElts, hVex, hVec, angle );
1418 if ( BadElement(hNewElts) ) return iElts;
1420 updateData(); //CS_TODO more or less?
1421 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1422 _elementsDirItem->appendRow(eltsItem);
1423 iElts = eltsItem->index();
1429 QModelIndex DocumentModel::makeSymmetryPoint( const QModelIndex& ielts, const QModelIndex& iv )
1433 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1434 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1436 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryPoint (hElts, hVex);
1437 if ( BadElement(hNewElts) ) return iElts;
1439 updateData(); //CS_TODO more or less?
1440 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1441 _elementsDirItem->appendRow(eltsItem);
1442 iElts = eltsItem->index();
1448 QModelIndex DocumentModel::makeSymmetryLine( const QModelIndex& ielts,
1449 const QModelIndex& iv,
1450 const QModelIndex& ivec )
1454 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1455 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1456 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1459 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryLine( hElts, hVex, hVec );
1460 if ( BadElement(hNewElts) ) return iElts;
1462 updateData(); //CS_TODO more or less?
1463 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1464 _elementsDirItem->appendRow(eltsItem);
1465 iElts = eltsItem->index();
1471 QModelIndex DocumentModel::makeSymmetryPlane( const QModelIndex& ielts, const QModelIndex& iv, const QModelIndex& ivec )
1475 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1476 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1477 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1479 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryPlane( hElts, hVex, hVec );
1480 if ( BadElement(hNewElts) ) return iElts;
1482 updateData(); //CS_TODO more or less?
1483 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1484 _elementsDirItem->appendRow(eltsItem);
1485 iElts = eltsItem->index();
1491 bool DocumentModel::performTranslation( const QModelIndex& ielts, const QModelIndex& ivec )
1493 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1494 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1496 int r = _hexaDocument->performTranslation (hElts, hVec);
1497 if ( r == HOK ){ //Job well done?
1507 bool DocumentModel::performScale( const QModelIndex& ielts, const QModelIndex& ivex, double k )
1509 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1510 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1512 int r = _hexaDocument->performScale (hElts, hVex, k);
1522 bool DocumentModel::performRotation( const QModelIndex& ielts, const QModelIndex& ivex, const QModelIndex& ivec, double angle )
1524 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1525 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1526 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1528 int r = _hexaDocument-> performRotation( hElts, hVex, hVec, angle );
1539 bool DocumentModel::performSymmetryPoint( const QModelIndex& ielts, const QModelIndex& ivex )
1541 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1542 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1544 int r = _hexaDocument->performSymmetryPoint( hElts, hVex );
1554 bool DocumentModel::performSymmetryLine( const QModelIndex& ielts, const QModelIndex& ivex, const QModelIndex& ivec )
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);
1560 int r = _hexaDocument->performSymmetryLine( hElts, hVex, hVec );
1570 bool DocumentModel::performSymmetryPlane( const QModelIndex& ielts,
1571 const QModelIndex& ivex,
1572 const QModelIndex& ivec )
1574 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1575 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1576 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1578 int r = _hexaDocument->performSymmetryPlane( hElts, hVex, hVec );
1587 QModelIndex DocumentModel::replace( const QModelIndexList& iquadsPattern,
1588 const QModelIndex& ip1, const QModelIndex& ic1,
1589 const QModelIndex& ip2, const QModelIndex& ic2,
1590 const QModelIndex& ip3, const QModelIndex& ic3 )
1594 HEXA_NS::Vertex* hp1 = getHexaPtr<HEXA_NS::Vertex*>(ip1);
1595 HEXA_NS::Vertex* hc1 = getHexaPtr<HEXA_NS::Vertex*>(ic1);
1596 HEXA_NS::Vertex* hp2 = getHexaPtr<HEXA_NS::Vertex*>(ip2);
1597 HEXA_NS::Vertex* hc2 = getHexaPtr<HEXA_NS::Vertex*>(ic2);
1598 HEXA_NS::Vertex* hp3 = getHexaPtr<HEXA_NS::Vertex*>(ip3);
1599 HEXA_NS::Vertex* hc3 = getHexaPtr<HEXA_NS::Vertex*>(ic3);
1601 HEXA_NS::Quads hquads;
1602 HEXA_NS::Quad* hquad = NULL;
1603 foreach( const QModelIndex& iquad, iquadsPattern ){
1604 hquad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1605 hquads.push_back( hquad );
1608 HEXA_NS::Elements* helts = _hexaDocument->replace( hquads,
1609 hp1, hc1, hp2, hc2, hp3, hc3 );
1610 if ( BadElement(helts) ) return ielts;
1613 ElementsItem* eltsItem = new ElementsItem(helts);
1614 _elementsDirItem->appendRow(eltsItem);
1615 ielts = eltsItem->index();
1620 QModelIndex DocumentModel::getGeomModelIndex(QString& id) const
1623 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1625 // ** get the model index of the geom element having this ID
1626 HEXA_NS::SubShape* eltPtr = getGeomPtr(id);
1627 HEXA_NS::VertexShape* geomVertex = dynamic_cast<HEXA_NS::VertexShape*>(eltPtr);
1628 HEXA_NS::EdgeShape* geomEdge = dynamic_cast<HEXA_NS::EdgeShape*>(eltPtr);
1629 HEXA_NS::FaceShape* geomFace = dynamic_cast<HEXA_NS::FaceShape*>(eltPtr);
1630 if (geomVertex != NULL)
1631 result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomVertex));
1632 if (geomEdge != NULL)
1633 result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomEdge));
1634 if (geomFace != NULL)
1635 result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomFace));
1640 QMultiMap< QString, int > DocumentModel::getAssocShapesIds(const QModelIndex& dataIndex)
1642 QMultiMap< QString, int > result;
1643 HEXA_NS::NewShape* mainShape;
1644 HEXA_NS::VertexShape* node;
1645 HEXA_NS::EdgeShape* line;
1646 HEXA_NS::FaceShape* face;
1650 PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
1651 QModelIndexList assocsInd = pdsm->getGeomAssociations(dataIndex);
1652 foreach( const QModelIndex& anAssoc, assocsInd )
1654 node = getHexaPtr<HEXA_NS::VertexShape*>(anAssoc);
1655 line = getHexaPtr<HEXA_NS::EdgeShape*>(anAssoc);
1656 face = getHexaPtr<HEXA_NS::FaceShape*>(anAssoc);
1660 mainShape = node->getParentShape();
1661 if (mainShape != NULL)
1663 shapeName = mainShape->getName();
1664 subid = node->getIdent();
1667 else if (line != NULL)
1669 mainShape = line->getParentShape();
1670 if (mainShape != NULL)
1672 shapeName = mainShape->getName();
1673 subid = line->getIdent();
1676 else if (face != NULL)
1678 mainShape = face->getParentShape();
1679 if (mainShape != NULL)
1681 shapeName = mainShape->getName();
1682 subid = face->getIdent();
1686 if (!shapeName.isEmpty())
1687 result.insert( shapeName, subid );
1689 shapeName = QString();
1694 bool DocumentModel::setVertexAssociation( const QModelIndex& iVertex, double x, double y, double z)
1696 HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex *>(iVertex);
1698 if (vertex == NULL || _hexaDocument == NULL || vertex->setAssociation(x, y, z) != HOK)
1701 HEXA_NS::VertexShape* assoc = vertex->getAssociation();
1704 HEXA_NS::NewShape* mainSh = assoc->getParentShape();
1705 setData( iVertex, QVariant::fromValue(QString(mainSh->getName())+","+QString::number(assoc->getIdent())+";"), HEXA_ASSOC_ENTRY_ROLE );
1711 bool DocumentModel::setVertexAssociation( const QModelIndex& iVertex, const QModelIndex& iGeomVertex)
1713 //parameters control
1715 HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex *>(iVertex);
1716 HEXA_NS::VertexShape* geomVertex = getHexaPtr<HEXA_NS::VertexShape*>(iGeomVertex);
1717 if (_hexaDocument == NULL || vertex == NULL || geomVertex == NULL) return false;
1718 HEXA_NS::NewShape* mainShape = geomVertex->getParentShape();
1719 if (mainShape == NULL) return false;
1722 if (vertex->setAssociation(geomVertex) != HOK)
1725 //update association state in the model
1726 newAssoc = QString(mainShape->getName()) + "," + QString::number(geomVertex->getIdent()) + ";";
1727 setData( iVertex, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1732 bool DocumentModel::addEdgeAssociation( const QModelIndex& iEdge, const QModelIndex& iGeomEdge, double start, double end)
1734 //parameters control
1735 QString currentAssoc, newAssoc;
1736 HEXA_NS::Edge* edge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
1737 HEXA_NS::EdgeShape* geomEdge = getHexaPtr<HEXA_NS::EdgeShape*>(iGeomEdge);
1738 if (_hexaDocument == NULL || edge == NULL ||
1739 geomEdge == NULL || start > end) return false;
1740 HEXA_NS::NewShape* mainShape = geomEdge->getParentShape();
1741 if (mainShape == NULL) return false;
1743 //add association in the engine side
1744 if (edge->addAssociation(geomEdge, start, end) != HOK)
1747 //add/update association in the model side (UI)
1748 currentAssoc = data(iEdge, HEXA_ASSOC_ENTRY_ROLE).toString();
1749 newAssoc = QString(mainShape->getName()) + "," + QString::number(geomEdge->getIdent()) + ";";
1750 if (!currentAssoc.isEmpty()) newAssoc = currentAssoc + newAssoc;
1752 setData( iEdge, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1758 bool DocumentModel::addQuadAssociation (const QModelIndex& iQuad, const QModelIndex& iGeomFace)
1760 //parameters control
1761 QString currentAssoc, newAssoc;
1762 HEXA_NS::Quad* quad = getHexaPtr<HEXA_NS::Quad*>(iQuad);
1763 HEXA_NS::FaceShape* geomFace = getHexaPtr<HEXA_NS::FaceShape*>(iGeomFace);
1764 if (_hexaDocument == NULL || quad == NULL || geomFace == NULL)
1766 HEXA_NS::NewShape* mainShape = geomFace->getParentShape();
1767 if (mainShape == NULL) return false;
1770 if (quad->addAssociation(geomFace) != HOK)
1773 //update association
1774 currentAssoc = data( iQuad, HEXA_ASSOC_ENTRY_ROLE).toString();
1775 newAssoc = QString(mainShape->getName()) + "," + QString::number(geomFace->getIdent()) + ";";
1776 if (!currentAssoc.isEmpty()) newAssoc = currentAssoc + newAssoc;
1777 setData( iQuad, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1783 QModelIndex DocumentModel::getVertexAssociation(const QModelIndex& iVertex)
1785 HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1787 return QModelIndex();
1789 //get the associated geom vertex
1790 HEXA_NS::VertexShape* geomVertex = vertex->getAssociation();
1791 if (geomVertex == NULL)
1792 return QModelIndex();
1794 //convert geom vertex to qmodelindex
1795 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1797 return QModelIndex();
1799 return pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(geomVertex));
1803 QModelIndexList DocumentModel::getEdgeAssociations(const QModelIndex& iEdge)
1805 QModelIndexList result;
1806 HEXA_NS::Edge* edge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
1807 if (edge == NULL) return result;
1809 HEXA_NS::EdgeShape* geomEdge;
1810 HEXA_NS::AssoEdge* anEdgeAssoc;
1812 PatternGeomSelectionModel* pGSModel = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1813 int nbAssocs = edge->countAssociation();
1814 for (int i = 0; i < nbAssocs; ++i)
1816 anEdgeAssoc = edge->getAssociation(i);
1817 if (anEdgeAssoc == NULL) continue;
1818 geomEdge = anEdgeAssoc->getEdgeShape();
1819 if (geomEdge == NULL) continue;
1820 result << pGSModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomEdge));
1827 QModelIndexList DocumentModel::getQuadAssociations(const QModelIndex& iQuad)
1829 QModelIndexList result;
1830 QModelIndex geomQuadIndex;
1831 HEXA_NS::Quad* quad = getHexaPtr<HEXA_NS::Quad*>(iQuad);
1832 if (quad == NULL) return result;
1834 if (HEXABLOCKGUI::currentDocGView == NULL) return result;
1835 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1836 PatternGeomModel* pgm = HEXABLOCKGUI::currentDocGView->getPatternGeomModel();
1837 if (pgsm == NULL || pgm == NULL) return result;
1839 HEXA_NS::FaceShape* geomFace;
1841 int nbAssocs = quad->countAssociation();
1842 for (int i = 0; i < nbAssocs; ++i)
1844 geomFace = quad->getAssociation(i);
1845 if (geomFace == NULL) continue;
1847 geomQuadIndex = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomFace) );
1848 result << geomQuadIndex;
1855 bool DocumentModel::associateOpenedLine( const QModelIndexList& iedges,
1856 HEXA_NS::NewShapes shapes,
1857 HEXA_NS::IntVector subIds,
1862 HEXA_NS::Edges mline;
1864 HEXA_NS::Edge* hedge = NULL;
1865 foreach( const QModelIndex& iedge, iedges ){
1866 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1868 mline.push_back( hedge );
1871 int err = _hexaDocument->associateOpenedLine( mline, shapes, subIds, pstart, pend );
1879 bool DocumentModel::associateClosedLine( const QModelIndex& ivertex,
1880 const QModelIndexList& iedges,
1881 HEXA_NS::NewShapes shapes,
1882 HEXA_NS::IntVector subIds,
1886 HEXA_NS::Vertex* mfirst = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1887 HEXA_NS::Edges mline;
1889 HEXA_NS::Edge* hedge = NULL;
1890 foreach( const QModelIndex& iedge, iedges ){
1891 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1893 mline.push_back( hedge );
1896 int err = _hexaDocument->associateClosedLine( mfirst, mline, shapes, subIds, pstart, inv);
1904 // ************ GROUPS ************
1906 QModelIndex DocumentModel::addGroup( const QString& name, Group kind )
1910 HEXA_NS::Group* hGroup = _hexaDocument->addGroup( name.toLocal8Bit().constData(), kind );
1911 if ( hGroup == NULL ) return iGroup;
1913 GroupItem* groupItem = new GroupItem(hGroup);
1914 groupItem->setData( _entry, HEXA_DOC_ENTRY_ROLE );
1915 _groupDirItem->appendRow(groupItem);
1916 iGroup = groupItem->index();
1922 bool DocumentModel::removeGroup( const QModelIndex& igrp )
1924 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1925 int r = _hexaDocument->removeGroup ( hGroup );
1928 removeRow( igrp.row(), igrp.parent());
1936 QModelIndexList DocumentModel::getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const
1938 QModelIndexList iElements;
1940 HEXA_NS::Group* g = iGroup.data(HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1941 if ( g == NULL ) return iElements;
1943 QModelIndexList iFound;
1945 HEXA_NS::EltBase* eltBase = NULL;
1946 int nbElement = g->countElement();
1947 for ( int nr = 0; nr < nbElement; ++nr ){
1948 eltBase = g->getElement( nr );
1949 kind = g->getKind();
1951 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: q = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
1952 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: q = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
1953 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: q = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
1954 case HEXA_NS::VertexNode: q = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
1956 iFound = match( index(0, 0),
1960 Qt::MatchRecursive );
1961 if ( !iFound.isEmpty() )
1962 iElements << iFound[0];
1967 // 7.4 Boite: éditer un groupe
1968 void DocumentModel::setGroupName( const QModelIndex& igrp, const QString& name )
1970 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1973 hGroup->setName( name.toLocal8Bit().constData() );
1974 setData(igrp, QVariant::fromValue( name ) );
1978 bool DocumentModel::addGroupElement( const QModelIndex& igrp, const QModelIndex& ielt )
1980 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1981 if (hGroup == NULL) return false;
1983 HEXA_NS::EltBase* hElt = NULL;
1984 switch ( hGroup->getKind() ){
1985 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: hElt = getHexaPtr<HEXA_NS::Hexa*>(ielt); break;
1986 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: hElt = getHexaPtr<HEXA_NS::Quad*>(ielt); break;
1987 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: hElt = getHexaPtr<HEXA_NS::Edge*>(ielt); break;
1988 case HEXA_NS::VertexNode: hElt = getHexaPtr<HEXA_NS::Vertex*>(ielt); break;
1993 res = hGroup->addElement( hElt );
1995 if ( res == HOK ) return true;
2000 bool DocumentModel::removeGroupElement( const QModelIndex& igrp, int nro )
2001 { //CS_TODO : remove child?
2002 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2003 if (hGroup == NULL) return false;
2005 if (hGroup->removeElement( nro ) == HOK) return true;
2010 bool DocumentModel::clearGroupElement( const QModelIndex& igrp )
2012 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2014 if ( hGroup != NULL)
2016 hGroup->clearElement();
2022 // ************ LAWS ************
2025 QModelIndex DocumentModel::addLaw( const QString& name, int nbnodes )
2029 HEXA_NS::Law* hLaw = _hexaDocument->addLaw( name.toLocal8Bit().constData(), nbnodes );
2030 if ( BadElement(hLaw) ) return iLaw;
2032 LawItem* lawItem = new LawItem(hLaw);
2033 _lawDirItem->appendRow(lawItem);
2034 iLaw = lawItem->index();
2039 bool DocumentModel::setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type )
2043 HEXA_NS::Law* hLaw = data(ilaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2047 ok = hLaw->setNodes( nbnodes );
2048 ( ok == HOK) ? ret = true : ret = false;
2049 ok = hLaw->setCoefficient( coeff );
2050 hLaw->setKind(type);
2057 bool DocumentModel::removeLaw( const QModelIndex& ilaw )
2059 HEXA_NS::Law* hLaw = data(ilaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2060 int r = _hexaDocument->removeLaw( hLaw );
2063 removeRow( ilaw.row(), ilaw.parent());
2070 bool DocumentModel::setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way )
2072 HEXA_NS::Propagation* hPropagation = data(iPropagation, HEXA_DATA_ROLE).value<HEXA_NS::Propagation *>();
2073 HEXA_NS::Law* hLaw = data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2075 int r = hPropagation->setLaw( hLaw );
2076 hPropagation->setWay( way );
2078 if ( r == HOK ) return true;
2084 QModelIndexList DocumentModel::getPropagation( const QModelIndex& iPropagation ) const
2086 QModelIndexList iEdges;
2088 QModelIndexList iFound;
2089 HEXA_NS::Propagation* propa = iPropagation.data(HEXA_DATA_ROLE).value<HEXA_NS::Propagation *>();
2090 if ( propa == NULL ) return iEdges;
2092 const HEXA_NS::Edges& edges = propa->getEdges();
2093 for ( HEXA_NS::Edges::const_iterator anEdge = edges.begin(), endIt = edges.end();
2096 iFound = match( index(0, 0),
2098 QVariant::fromValue( *anEdge ),
2100 Qt::MatchRecursive);
2101 if ( !iFound.isEmpty() )
2102 iEdges << iFound[0];
2108 HEXA_NS::Document* DocumentModel::documentImpl()
2110 return _hexaDocument;
2113 QString DocumentModel::documentEntry()
2118 // 8.3 Boite: éditer une loi CS_TODO
2121 /*****************************************************************
2123 *****************************************************************/
2125 PatternDataModel::PatternDataModel( QObject * parent ) :
2126 QSortFilterProxyModel( parent )
2128 QString dataRegExp = QString("(%1|%2|%3|%4|%5|%6|%7|%8)").
2129 arg(VERTEX_TREE).arg(EDGE_TREE).arg(QUAD_TREE).arg(HEXA_TREE).
2130 arg(VERTEX_DIR_TREE).arg(EDGE_DIR_TREE).arg(QUAD_DIR_TREE).arg(HEXA_DIR_TREE);
2132 setFilterRole(HEXA_TREE_ROLE);
2133 setFilterRegExp ( QRegExp(dataRegExp) );
2136 // *** Pour suppression des panneaux "Builder" et "Geometry" ****/
2138 //PatternDataModel::PatternDataModel( QObject * parent ) :
2139 // QSortFilterProxyModel( parent )
2141 // 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)").
2142 // arg(VERTEX_TREE).arg(EDGE_TREE).arg(QUAD_TREE).arg(HEXA_TREE).
2143 // arg(VERTEX_DIR_TREE).arg(EDGE_DIR_TREE).arg(QUAD_DIR_TREE).
2144 // arg(HEXA_DIR_TREE).arg(VECTOR_TREE).arg(ELEMENTS_TREE).
2145 // arg(VECTOR_DIR_TREE).arg(ELEMENTS_DIR_TREE).
2146 // arg(IMPLICIT_SHAPES_TREE).arg(EXPLICIT_SHAPES_TREE).arg(CLOUD_OF_POINTS_TREE).
2147 // arg(GEOMSHAPE_TREE).arg(GEOMPOINT_TREE).arg(GEOMEDGE_TREE).arg(GEOMFACE_TREE).
2148 // arg(IMPLICIT_SHAPES_DIR_TREE).arg(EXPLICIT_SHAPES_DIR_TREE).arg(CLOUD_OF_POINTS_DIR_TREE).
2149 // arg(GEOMSHAPE_DIR_TREE).arg(GEOMPOINT_DIR_TREE).arg(GEOMEDGE_DIR_TREE).arg(GEOMFACE_DIR_TREE);
2151 // setFilterRole(HEXA_TREE_ROLE);
2152 // setFilterRegExp ( QRegExp(dataRegExp) );
2157 PatternDataModel::~PatternDataModel()
2161 HEXA_NS::Document* PatternDataModel::documentImpl()
2163 HEXA_NS::Document* doc = NULL;
2164 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2165 if (m) doc = m->documentImpl();
2169 QString PatternDataModel::documentEntry()
2172 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2173 if (m) entry = m->documentEntry();
2177 Qt::ItemFlags PatternDataModel::flags(const QModelIndex &index) const
2179 Qt::ItemFlags flags;
2181 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2183 flags = m->flags( mapToSource(index) );
2189 QVariant PatternDataModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2191 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2192 return QVariant( "Data" );
2194 return QSortFilterProxyModel::headerData ( section, orientation, role );
2199 QStandardItem* PatternDataModel::itemFromIndex ( const QModelIndex & index ) const
2201 QStandardItem *item = NULL;
2202 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2204 item = m->itemFromIndex( mapToSource(index) );
2209 PatternBuilderModel::PatternBuilderModel( QObject * parent ) :
2210 QSortFilterProxyModel( parent )
2212 QString builderRegExp =QString("(%1|%2|%3|%4|%5|%6)").
2213 arg(VECTOR_TREE).arg(ELEMENTS_TREE).
2214 arg(CROSSELEMENTS_TREE).arg(VECTOR_DIR_TREE).arg(ELEMENTS_DIR_TREE).arg(CROSSELEMENTS_DIR_TREE);
2216 setFilterRole( HEXA_TREE_ROLE );
2217 setFilterRegExp ( QRegExp( builderRegExp ) );
2220 PatternBuilderModel::~PatternBuilderModel()
2224 Qt::ItemFlags PatternBuilderModel::flags(const QModelIndex &index) const
2226 Qt::ItemFlags flags;
2228 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2230 flags = m->flags( mapToSource(index) );
2235 QVariant PatternBuilderModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2237 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2238 return QVariant( "Builder" );
2240 return QSortFilterProxyModel::headerData ( section, orientation, role );
2244 QStandardItem* PatternBuilderModel::itemFromIndex ( const QModelIndex & index ) const
2246 QStandardItem *item = NULL;
2247 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2249 item = m->itemFromIndex( mapToSource(index) );
2254 //====================================================================
2256 //====================================================================
2257 PatternGeomModel::PatternGeomModel( QObject * parent ) :
2258 QSortFilterProxyModel( parent )
2260 QString builderRegExp =QString("(%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12|%13|%14)").
2261 arg(EXPLICIT_SHAPES_TREE).arg(IMPLICIT_SHAPES_TREE).arg(CLOUD_OF_POINTS_TREE).
2262 arg(GEOMSHAPE_TREE).arg(GEOMPOINT_TREE).arg(GEOMEDGE_TREE).arg(GEOMFACE_TREE).
2263 arg(EXPLICIT_SHAPES_DIR_TREE).arg(IMPLICIT_SHAPES_DIR_TREE).arg(CLOUD_OF_POINTS_DIR_TREE).
2264 arg(GEOMSHAPE_DIR_TREE).arg(GEOMPOINT_DIR_TREE).arg(GEOMEDGE_DIR_TREE).arg(GEOMFACE_DIR_TREE);
2266 setFilterRole( HEXA_TREE_ROLE );
2267 setFilterRegExp ( QRegExp(builderRegExp ) );
2270 PatternGeomModel::~PatternGeomModel()
2274 Qt::ItemFlags PatternGeomModel::flags(const QModelIndex &index) const
2276 Qt::ItemFlags flags;
2278 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2280 flags = m->flags( mapToSource(index) );
2285 QVariant PatternGeomModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2287 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2288 return QVariant( "Geometry" );
2290 return QSortFilterProxyModel::headerData ( section, orientation, role );
2294 QStandardItem* PatternGeomModel::itemFromIndex ( const QModelIndex & index ) const
2296 QStandardItem *item = NULL;
2297 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2299 item = m->itemFromIndex( mapToSource(index) );
2303 //==============================================================
2306 AssociationsModel::AssociationsModel( QObject * parent ) :
2307 QSortFilterProxyModel( parent )
2309 QString assocRegExp;
2311 setFilterRole( HEXA_TREE_ROLE );
2312 setFilterRegExp ( QRegExp(assocRegExp) );
2315 AssociationsModel::~AssociationsModel()
2319 Qt::ItemFlags AssociationsModel::flags(const QModelIndex &index) const
2321 Qt::ItemFlags flags;
2323 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2325 flags = m->flags( mapToSource(index) );
2330 QVariant AssociationsModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2332 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2333 return QVariant( "Associations" );
2335 return QSortFilterProxyModel::headerData ( section, orientation, role );
2339 QStandardItem* AssociationsModel::itemFromIndex ( const QModelIndex & index ) const
2341 QStandardItem *item = NULL;
2342 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2344 item = m->itemFromIndex( mapToSource(index) );
2349 GroupsModel::GroupsModel( QObject * parent ) :
2350 QSortFilterProxyModel( parent )
2352 QString groupsRegExp =QString("(%1|%2)").arg(GROUP_TREE).arg(GROUP_DIR_TREE);
2354 setFilterRole( HEXA_TREE_ROLE );
2355 setFilterRegExp ( QRegExp(groupsRegExp ) );
2358 GroupsModel::~GroupsModel()
2362 Qt::ItemFlags GroupsModel::flags(const QModelIndex &index) const
2364 Qt::ItemFlags flags;
2366 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2368 flags = m->flags( mapToSource(index) );
2373 QVariant GroupsModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2375 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2376 return QVariant( "Groups" );
2378 return QSortFilterProxyModel::headerData ( section, orientation, role );
2382 QStandardItem* GroupsModel::itemFromIndex ( const QModelIndex & index ) const
2384 QStandardItem *item = NULL;
2385 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2387 item = m->itemFromIndex( mapToSource(index) );
2392 QModelIndexList GroupsModel::getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const
2394 QModelIndexList elements;
2395 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2397 elements = m->getGroupElements( mapToSource(iGroup), kind );
2402 MeshModel::MeshModel( QObject * parent ) :
2403 QSortFilterProxyModel( parent )
2405 QString meshRegExp =QString("(%1|%2|%3|%4)").arg(LAW_TREE).arg(LAW_DIR_TREE) .arg(PROPAGATION_TREE).arg(PROPAGATION_DIR_TREE);
2407 setFilterRole( HEXA_TREE_ROLE );
2408 setFilterRegExp ( QRegExp(meshRegExp) );
2411 MeshModel::~MeshModel()
2415 Qt::ItemFlags MeshModel::flags(const QModelIndex &index) const
2417 Qt::ItemFlags flags;
2419 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2421 flags = m->flags( mapToSource(index) );
2426 QVariant MeshModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2428 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2429 return QVariant( "Mesh" );
2431 return QSortFilterProxyModel::headerData ( section, orientation, role );
2435 QStandardItem* MeshModel::itemFromIndex ( const QModelIndex & index ) const
2437 QStandardItem *item = NULL;
2438 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2440 item = m->itemFromIndex( mapToSource(index) );
2445 QModelIndexList MeshModel::getPropagation( const QModelIndex& iPropagation ) const
2447 QModelIndexList edges;
2448 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2450 edges = m->getPropagation( mapToSource(iPropagation) );
2456 // ================================== NEW ======================================
2458 // ===== CARTESIAN GRID
2460 QModelIndex DocumentModel::makeCartesianTop(int nx, int ny, int nz)
2464 HEXA_NS::Elements* helts = _hexaDocument->makeCartesianTop( nx, ny, nz );
2465 if ( BadElement(helts) )
2468 result = addElementsToTree(helts, _elementsDirItem);
2473 QModelIndex DocumentModel::makeCartesianUni(const QModelIndex& icenter,
2474 const QModelIndex& ibase, const QModelIndex& ivec, const QModelIndex& iaxis,
2475 double lx, double ly, double lz, int nx, int ny, int nz)
2479 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2480 HEXA_NS::Vector* hbase = getHexaPtr<HEXA_NS::Vector*>(ibase);
2481 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(ivec);
2482 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2484 HEXA_NS::Elements* helts = _hexaDocument->makeCartesianUni( hcenter, hbase, hvec, haxis,
2485 lx, ly, lz, nx, ny, nz);
2486 if ( BadElement(helts) )
2489 result = addElementsToTree(helts, _elementsDirItem);
2494 QModelIndex DocumentModel::makeCartesian(const QModelIndex& icenter,
2495 const QModelIndex& ibase, const QModelIndex& ivec, const QModelIndex& iaxis,
2496 vector<double>& radius, vector<double>& angles, vector<double>& heights)
2500 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2501 HEXA_NS::Vector* hbase = getHexaPtr<HEXA_NS::Vector*>(ibase);
2502 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(ivec);
2503 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2505 HEXA_NS::Elements* helts = _hexaDocument->makeCartesian( hcenter, hbase, hvec, haxis,
2506 radius, angles, heights);
2507 if ( BadElement(helts) )
2510 result = addElementsToTree(helts, _elementsDirItem);
2518 QModelIndex DocumentModel::makeSphereTop (int nr, int na, int nh)
2522 HEXA_NS::Elements* helts = _hexaDocument->makeSphereTop( nr, na, nh );
2523 if ( BadElement(helts) )
2526 result = addElementsToTree(helts, _elementsDirItem);
2531 QModelIndex DocumentModel::makeSphereUni (QModelIndex& icenter,
2532 QModelIndex& ivec_x, QModelIndex& ivec_z,
2533 double rtrou, double rext, double ang,
2534 QModelIndex& ivplan,
2535 int nr, int na, int nh)
2539 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2540 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2541 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2542 HEXA_NS::Vertex* hvplan = getHexaPtr<HEXA_NS::Vertex*>(ivplan);
2544 HEXA_NS::Elements* helts = _hexaDocument->makeSphereUni( hcenter, hvec_x, hvec_z,
2545 rtrou, rext, ang, hvplan,
2547 result = addElementsToTree(helts, _elementsDirItem);
2552 QModelIndex DocumentModel::makeSphere (QModelIndex& icenter,
2553 QModelIndex& ivec_x, QModelIndex& ivec_z,
2554 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2558 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2559 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2560 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2562 HEXA_NS::Elements* helts = _hexaDocument->makeSphere( hcenter, hvec_x, hvec_z,
2565 result = addElementsToTree(helts, _elementsDirItem);
2572 QModelIndex DocumentModel::makeSphericalTop (int nbre, int crit)
2576 HEXA_NS::Elements* helts = _hexaDocument->makeSphericalTop(nbre, crit);
2577 if (BadElement(helts))
2580 result = addElementsToTree(helts, _elementsDirItem);
2585 QModelIndex DocumentModel::makeSphericalUni (QModelIndex& icenter,
2586 QModelIndex& ivec_x, QModelIndex& ivec_z,
2592 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2593 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2594 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2596 HEXA_NS::Elements* helts = _hexaDocument->makeSphericalUni(hcenter, hvec_x, hvec_z, rayon, nbre, crit);
2597 if (BadElement(helts))
2600 result = addElementsToTree(helts, _elementsDirItem);
2605 QModelIndex DocumentModel::makeSpherical (QModelIndex& icenter,
2606 QModelIndex& ivec_x, QModelIndex& ivec_z,
2607 vector<double>& rayon,
2612 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2613 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2614 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2616 HEXA_NS::Elements* helts = _hexaDocument->makeSpherical(hcenter, hvec_x, hvec_z, rayon, crit);
2617 if (BadElement(helts))
2620 result = addElementsToTree(helts, _elementsDirItem);
2626 QModelIndex DocumentModel::makeRindTop (int nr, int na, int nh)
2630 HEXA_NS::Elements* helts = _hexaDocument->makeRindTop(nr, na, nh);
2631 if (BadElement(helts))
2634 result = addElementsToTree(helts, _elementsDirItem);
2639 QModelIndex DocumentModel::makeRindUni (QModelIndex& icenter,
2640 QModelIndex& ivec_x, QModelIndex& ivec_z,
2641 double raytrou, double rint, double rext, double ang,
2642 QModelIndex& ivplan,
2643 int nr, int na, int nh)
2647 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2648 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2649 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2650 HEXA_NS::Vertex* hvplan = getHexaPtr<HEXA_NS::Vertex*>(ivplan);
2652 HEXA_NS::Elements* helts = _hexaDocument->makeRindUni(hcenter, hvec_x, hvec_z, raytrou, rint, rext, ang,
2653 hvplan, nr, na, nh);
2654 if (BadElement(helts))
2657 result = addElementsToTree(helts, _elementsDirItem);
2662 QModelIndex DocumentModel::makeRind (QModelIndex& icenter,
2663 QModelIndex& ivec_x, QModelIndex& ivec_z,
2664 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2668 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2669 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2670 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2672 HEXA_NS::Elements* helts = _hexaDocument->makeRind(hcenter, hvec_x, hvec_z, tray, tang, thaut);
2673 if (BadElement(helts))
2676 result = addElementsToTree(helts, _elementsDirItem);
2681 // ======== Cylinder
2682 QModelIndex DocumentModel::makeCylinderTop(int nr, int na, int nh)
2686 HEXA_NS::Elements* helts = _hexaDocument->makeCylinderTop(nr, na, nh);
2687 if (BadElement(helts))
2690 result = addElementsToTree(helts, _elementsDirItem);
2695 QModelIndex DocumentModel::makeCylinderUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2696 double rint, double rext, double angle, double haut,
2697 int nr, int na, int nh)
2701 HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2702 HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2703 HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2705 HEXA_NS::Elements* helts = _hexaDocument->makeCylinderUni(horig, hvecx, hvecz,
2706 rint, rext, angle, haut,
2708 if (BadElement(helts))
2711 result = addElementsToTree(helts, _elementsDirItem);
2716 QModelIndex DocumentModel::makeCylinder(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2717 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2721 HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2722 HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2723 HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2725 HEXA_NS::Elements* helts = _hexaDocument->makeCylinder(horig, hvecx, hvecz, tray, tang, thaut);
2726 if (BadElement(helts))
2729 result = addElementsToTree(helts, _elementsDirItem);
2735 // ======== Cylinders
2736 QModelIndex DocumentModel::makeCylinders(QModelIndex& iorig1, QModelIndex& ivecz1, double r1, double h1,
2737 QModelIndex& iorig2, QModelIndex& ivecz2, double r2, double h2)
2741 HEXA_NS::Vertex* horig1 = getHexaPtr<HEXA_NS::Vertex*>(iorig1);
2742 HEXA_NS::Vertex* horig2 = getHexaPtr<HEXA_NS::Vertex*>(iorig2);
2743 HEXA_NS::Vector* hvecz1 = getHexaPtr<HEXA_NS::Vector*>(ivecz1);
2744 HEXA_NS::Vector* hvecz2 = getHexaPtr<HEXA_NS::Vector*>(ivecz2);
2746 HEXA_NS::BiCylinder* helts = _hexaDocument->makeCylinders(horig1, hvecz1, r1, h1,
2747 horig2, hvecz2, r2, h2);
2748 if (BadElement(helts))
2751 result = addElementsToTree(helts, _crossElementsDirItem);
2757 QModelIndex DocumentModel::makePipeTop(int nr, int na, int nh)
2761 HEXA_NS::Elements* helts = _hexaDocument->makePipeTop(nr, na, nh);
2762 if (BadElement(helts))
2765 result = addElementsToTree(helts, _elementsDirItem);
2770 QModelIndex DocumentModel::makePipeUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2771 double rint, double rext, double angle, double haut,
2772 int nr, int na, int nh)
2776 HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2777 HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2778 HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2780 HEXA_NS::Elements* helts = _hexaDocument->makePipeUni(horig, hvecx, hvecz, rint, rext, angle,
2782 if (BadElement(helts))
2785 result = addElementsToTree(helts, _elementsDirItem);
2790 QModelIndex DocumentModel::makePipe(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2791 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2795 HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2796 HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2797 HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2799 HEXA_NS::Elements* helts = _hexaDocument->makePipe(horig, hvecx, hvecz, tray, tang, thaut);
2800 if (BadElement(helts))
2803 result = addElementsToTree(helts, _elementsDirItem);
2809 QModelIndex DocumentModel::makePipes(QModelIndex& iorig1, QModelIndex& ivecz1, double rint1, double rex1, double h1,
2810 QModelIndex& iorig2, QModelIndex& ivecz2, double rint2, double rex2, double h2)
2814 HEXA_NS::Vertex* horig1 = getHexaPtr<HEXA_NS::Vertex*>(iorig1);
2815 HEXA_NS::Vertex* horig2 = getHexaPtr<HEXA_NS::Vertex*>(iorig2);
2816 HEXA_NS::Vector* hvecz1 = getHexaPtr<HEXA_NS::Vector*>(ivecz1);
2817 HEXA_NS::Vector* hvecz2 = getHexaPtr<HEXA_NS::Vector*>(ivecz2);
2819 HEXA_NS::BiCylinder* helts = _hexaDocument->makePipes(horig1, hvecz1, rint1, rex1, h1,
2820 horig2, hvecz2, rint2, rex2, h2);
2821 if (BadElement(helts))
2824 result = addElementsToTree(helts, _crossElementsDirItem);
2829 // ======== Join Quads
2830 QModelIndex DocumentModel::joinQuadUni(QModelIndex& istart, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
2831 QModelIndex& iv3, QModelIndex& iv4, int nb)
2835 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
2836 HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
2837 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
2838 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
2839 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
2840 HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
2842 HEXA_NS::Elements* helts = _hexaDocument->joinQuadUni(hstart, hdest, hv1, hv2, hv3, hv4, nb);
2843 if (BadElement(helts))
2846 result = addElementsToTree(helts, _elementsDirItem);
2851 QModelIndex DocumentModel::joinQuad(QModelIndex& istart, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
2852 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen)
2856 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
2857 HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
2858 HEXA_NS::Vertex* hva1 = getHexaPtr<HEXA_NS::Vertex*>(iva1);
2859 HEXA_NS::Vertex* hvb1 = getHexaPtr<HEXA_NS::Vertex*>(ivb1);
2860 HEXA_NS::Vertex* hva2 = getHexaPtr<HEXA_NS::Vertex*>(iva2);
2861 HEXA_NS::Vertex* hvb2 = getHexaPtr<HEXA_NS::Vertex*>(ivb2);
2863 HEXA_NS::Elements* helts = _hexaDocument->joinQuad(hstart, hdest, hva1, hvb1, hva2, hvb2, tlen);
2864 if (BadElement(helts))
2867 result = addElementsToTree(helts, _elementsDirItem);
2872 QModelIndex DocumentModel::joinQuadsUni(QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
2873 QModelIndex& iv3, QModelIndex& iv4, int nb)
2877 HEXA_NS::Quads hstarts;
2878 int nbQuads = istarts.size();
2879 for (int i = 0; i < nbQuads; ++i)
2880 hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
2882 HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
2883 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
2884 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
2885 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
2886 HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
2888 HEXA_NS::Elements* helts = _hexaDocument->joinQuadsUni(hstarts, hdest, hv1, hv2, hv3, hv4, nb);
2889 if (BadElement(helts))
2892 result = addElementsToTree(helts, _elementsDirItem);
2897 QModelIndex DocumentModel::joinQuads(QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
2898 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen)
2902 HEXA_NS::Quads hstarts;
2903 int nbQuads = istarts.size();
2904 for (int i = 0; i < nbQuads; ++i)
2905 hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
2907 HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
2908 HEXA_NS::Vertex* hva1 = getHexaPtr<HEXA_NS::Vertex*>(iva1);
2909 HEXA_NS::Vertex* hvb1 = getHexaPtr<HEXA_NS::Vertex*>(ivb1);
2910 HEXA_NS::Vertex* hva2 = getHexaPtr<HEXA_NS::Vertex*>(iva2);
2911 HEXA_NS::Vertex* hvb2 = getHexaPtr<HEXA_NS::Vertex*>(ivb2);
2913 HEXA_NS::Elements* helts = _hexaDocument->joinQuads(hstarts, hdest, hva1, hvb1, hva2, hvb2, tlen);
2914 if (BadElement(helts))
2917 result = addElementsToTree(helts, _elementsDirItem);
2922 // ======== Quad Revolution
2923 QModelIndex DocumentModel::revolutionQuadUni(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
2924 double angle, int nbre)
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);
2932 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuadUni(hstart, hcenter, haxis, angle, nbre);
2933 if (BadElement(helts))
2936 result = addElementsToTree(helts, _elementsDirItem);
2941 QModelIndex DocumentModel::revolutionQuad(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
2942 vector<double>& angles)
2946 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
2947 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2948 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2950 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuad(hstart, hcenter, haxis, angles);
2951 if (BadElement(helts))
2954 result = addElementsToTree(helts, _elementsDirItem);
2959 QModelIndex DocumentModel::revolutionQuadsUni(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
2960 double angle, int nbre)
2964 HEXA_NS::Quads hstarts;
2965 int nbQuads = istarts.count();
2966 for (int i = 0; i < nbQuads; ++i)
2967 hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
2969 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2970 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2972 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuadsUni(hstarts, hcenter, haxis, angle, nbre);
2973 if (BadElement(helts))
2976 result = addElementsToTree(helts, _elementsDirItem);
2981 QModelIndex DocumentModel::revolutionQuads(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
2982 vector<double>& angles)
2986 HEXA_NS::Quads hstarts;
2987 int nbQuads = istarts.count();
2988 for (int i = 0; i < nbQuads; ++i)
2989 hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
2991 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2992 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2994 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuads(hstarts, hcenter, haxis, angles);
2995 if (BadElement(helts))
2998 result = addElementsToTree(helts, _elementsDirItem);
3004 // ==== PrismQuad or ExtrudeQuad
3005 QModelIndex DocumentModel::extrudeQuadTop(QModelIndex& istart, int nbre)
3009 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3010 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadTop(hstart, nbre);
3011 if (BadElement(helts))
3014 result = addElementsToTree(helts, _elementsDirItem);
3019 QModelIndex DocumentModel::extrudeQuadUni(QModelIndex& istart, QModelIndex& dv, double len, int nbre)
3023 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3024 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(dv);
3026 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadUni(hstart, hvec, len, nbre);
3027 if (BadElement(helts))
3030 result = addElementsToTree(helts, _elementsDirItem);
3035 QModelIndex DocumentModel::extrudeQuad(QModelIndex& istart, QModelIndex& dv, vector<double>& tlen)
3039 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3040 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(dv);
3042 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuad(hstart, hvec, tlen);
3043 if (BadElement(helts))
3045 result = addElementsToTree(helts, _elementsDirItem);
3050 QModelIndex DocumentModel::extrudeQuadsTop (QModelIndexList& istarts, int nbre)
3054 HEXA_NS::Quads hquads;
3055 int nbQuads = istarts.count();
3056 for (int i = 0; i < nbQuads; ++i)
3057 hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3059 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadsTop(hquads, nbre);
3060 if (BadElement(helts))
3062 result = addElementsToTree(helts, _elementsDirItem);
3067 QModelIndex DocumentModel::extrudeQuadsUni (QModelIndexList& istarts, QModelIndex& axis, double len, int nbre)
3071 HEXA_NS::Quads hquads;
3072 int nbQuads = istarts.count();
3073 for (int i = 0; i < nbQuads; ++i)
3074 hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3076 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(axis);
3078 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadsUni(hquads, haxis, len, nbre);
3079 if (BadElement(helts))
3081 result = addElementsToTree(helts, _elementsDirItem);
3086 QModelIndex DocumentModel::extrudeQuads(QModelIndexList& istarts, QModelIndex& iaxis, vector<double>& tlen)
3090 HEXA_NS::Quads hquads;
3091 int nbQuads = istarts.count();
3092 for (int i=0; i < nbQuads; ++i)
3093 hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3095 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3097 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuads(hquads, haxis, tlen);
3098 if (BadElement(helts))
3100 result = addElementsToTree(helts, _elementsDirItem);
3106 QModelIndex DocumentModel::cutUni(QModelIndex& iEdge, int nbre)
3110 HEXA_NS::Edge* hedge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
3112 HEXA_NS::Elements* helts = _hexaDocument->cutUni(hedge, nbre);
3113 if (BadElement(helts))
3115 result = addElementsToTree(helts, _elementsDirItem);
3120 QModelIndex DocumentModel::cut(QModelIndex& iEdge, vector<double>& tlen)
3124 HEXA_NS::Edge* hedge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
3126 HEXA_NS::Elements* helts = _hexaDocument->cut(hedge, tlen);
3127 if (BadElement(helts))
3129 result = addElementsToTree(helts, _elementsDirItem);
3134 // ================================== END NEW ==================================