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::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;
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);
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;
1004 QuadItem* q = new QuadItem(hq, _entry);
1005 _quadDirItem->appendRow(q);
1006 quadIndex = q->index();
1007 emit patternDataChanged();
1013 QModelIndex DocumentModel::addQuadEdges( const QModelIndex &e0, const QModelIndex &e1,
1014 const QModelIndex &e2, const QModelIndex &e3 )
1016 QModelIndex quadIndex;
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);
1023 if ( he0 and he1 and he2 and he3 ){
1025 HEXA_NS::Quad* hq = _hexaDocument->addQuad( he0, he1, he2, he3 );
1026 if ( BadElement(hq) ) return quadIndex;
1028 QuadItem* q = new QuadItem(hq, _entry);
1029 _quadDirItem->appendRow(q);
1030 quadIndex = q->index();
1031 emit patternDataChanged();
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 )
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);
1054 HEXA_NS::Hexa* hh = _hexaDocument->addHexaVertices( hv0, hv1, hv2, hv3,
1055 hv4, hv5, hv6, hv7 );
1057 if ( BadElement(hh) ) return iHexa;
1059 HexaItem* h = new HexaItem(hh, _entry);
1060 _hexaDirItem->appendRow(h);
1062 emit patternDataChanged();
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;
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);
1079 HEXA_NS::Hexa* hh = _hexaDocument->addHexa( hq0, hq1, hq2, hq3, hq4, hq5 );
1080 if ( BadElement(hh) ) return hexaIndex;
1082 HexaItem* h = new HexaItem(hh, _entry);
1083 _hexaDirItem->appendRow(h);
1084 hexaIndex = h->index();
1085 emit patternDataChanged();
1090 QModelIndex DocumentModel::addHexaQuads( const QModelIndexList &iquads)
1092 QModelIndex hexaIndex;
1094 HEXA_NS::Hexa* hh = NULL;
1095 HEXA_NS::Quad* hq0, *hq1, *hq2, *hq3, *hq4, *hq5 = NULL;
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));
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);
1115 if ( BadElement(hh) ) return hexaIndex;
1118 unsigned int nbRows = _hexaDirItem->rowCount();
1120 hexaIndex = _hexaDirItem->child(nbRows-1)->index();
1125 QModelIndex DocumentModel::addVector( double dx, double dy, double dz )
1127 QModelIndex vectorIndex;
1129 HEXA_NS::Vector* hv = _hexaDocument->addVector(dx, dy, dz);
1130 if ( BadElement(hv) ) return vectorIndex; //Invalid index
1132 VectorItem* v = new VectorItem(hv);
1133 _vectorDirItem->appendRow(v);
1134 vectorIndex = v->index();
1139 QModelIndex DocumentModel::addVectorVertices( const QModelIndex &iv0, const QModelIndex &iv1 )
1143 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1144 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1146 HEXA_NS::Vector* hvec = _hexaDocument->addVectorVertices( hv0, hv1 );
1147 if ( BadElement(hvec) ) return iVec;
1149 VectorItem* vec = new VectorItem(hvec);
1150 _vectorDirItem->appendRow(vec);
1151 iVec = vec->index();
1157 // ************ EDIT HEXABLOCK MODEL ************
1159 bool DocumentModel::updateVertex( const QModelIndex& ivertex, double x, double y, double z )
1163 HEXA_NS::Vertex* hVertex = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1166 // hVertex->setName( name.toStdString() );
1167 hVertex->setX ( x );
1168 hVertex->setY ( y );
1169 hVertex->setZ ( z );
1170 emit patternDataChanged();
1177 bool DocumentModel::removeHexa( const QModelIndex& ihexa )
1179 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1181 int r = _hexaDocument->removeHexa( hHexa );
1190 bool DocumentModel::removeConnectedHexa( const QModelIndex& ihexa )
1192 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1194 int r = _hexaDocument->removeConnectedHexa( hHexa );
1203 bool DocumentModel::mergeVertices( const QModelIndex &iv0, const QModelIndex &iv1 ) //CS_TODO : impact sur le model?
1205 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1206 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1208 int r = _hexaDocument->mergeVertices( hv0, hv1 );
1210 updateData(); //CS_TODO more or less?
1217 bool DocumentModel::mergeEdges( const QModelIndex &ie0, const QModelIndex &ie1,
1218 const QModelIndex &iv0, const QModelIndex &iv1 )
1219 //CS_TODO : impact sur le model?
1221 HEXA_NS::Edge* he0 = getHexaPtr<HEXA_NS::Edge*>(ie0);
1222 HEXA_NS::Edge* he1 = getHexaPtr<HEXA_NS::Edge*>(ie1);
1224 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1225 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1228 int r = _hexaDocument->mergeEdges( he0, he1, hv0, hv1 );
1237 bool DocumentModel::mergeQuads( const QModelIndex& iquad0, const QModelIndex& iquad1,
1238 const QModelIndex& iv0, const QModelIndex& iv1,
1239 const QModelIndex& iv2, const QModelIndex& iv3 )
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 *>();
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);
1249 int r = _hexaDocument->mergeQuads( hquad0, hquad1, hv0, hv1, hv2, hv3 );
1259 QModelIndex DocumentModel::disconnectVertex( const QModelIndex& ihexa, const QModelIndex& ivertex )
1263 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1264 HEXA_NS::Vertex* hVertex = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1266 HEXA_NS::Elements* hElts = _hexaDocument->disconnectVertex( hHexa, hVertex );
1267 if ( BadElement(hElts) ) return iElts;
1269 updateData(); //CS_TO_CHECK
1270 ElementsItem* elts = new ElementsItem(hElts);
1271 _elementsDirItem->appendRow(elts);
1272 iElts = elts->index();
1277 QModelIndex DocumentModel::disconnectEdge( const QModelIndex& ihexa, const QModelIndex& iedge )
1281 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1282 HEXA_NS::Edge* hEdge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1284 HEXA_NS::Elements* hElts = _hexaDocument->disconnectEdge( hHexa, hEdge );
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();
1296 QModelIndex DocumentModel::disconnectEdges( const QModelIndexList& ihexas, const QModelIndexList& iedges )
1300 HEXA_NS::Hexas hHexas;
1301 HEXA_NS::Edges hEdges;
1304 HEXA_NS::Edge* hedge = NULL;
1305 foreach( const QModelIndex& iedge, iedges ){
1306 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1307 hEdges.push_back( hedge );
1311 HEXA_NS::Hexa* hhexa = NULL;
1312 foreach( const QModelIndex& ihexa, ihexas ){
1313 hhexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1314 hHexas.push_back( hhexa );
1318 HEXA_NS::Elements* hElts = _hexaDocument->disconnectEdges( hHexas, hEdges );
1319 if ( BadElement(hElts) ) return iElts;
1321 updateData(); //CS_TO_CHECK
1322 ElementsItem* elts = new ElementsItem(hElts);
1323 _elementsDirItem->appendRow(elts);
1324 iElts = elts->index();
1330 QModelIndex DocumentModel::disconnectQuad( const QModelIndex& ihexa, const QModelIndex& iquad )
1334 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1335 HEXA_NS::Quad* hQuad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1337 HEXA_NS::Elements* hElts = _hexaDocument->disconnectQuad( hHexa, hQuad );
1338 if ( BadElement(hElts) ) return iElts;
1340 updateData(); //CS_TO_CHECK
1341 ElementsItem* elts = new ElementsItem(hElts);
1342 _elementsDirItem->appendRow(elts);
1343 iElts = elts->index();
1349 QModelIndex DocumentModel::makeTranslation( const QModelIndex& ielts, const QModelIndex& ivec )
1353 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1354 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1356 HEXA_NS::Elements* hNewElts = _hexaDocument->makeTranslation( hElts, hVec );
1357 if ( BadElement(hNewElts) ) return iElts;
1359 updateData(); //CS_TODO more or less?
1360 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1361 _elementsDirItem->appendRow(eltsItem);
1362 iElts = eltsItem->index();
1369 QModelIndex DocumentModel::makeScale( const QModelIndex& ielts, const QModelIndex& ivex, double k )
1373 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1374 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1376 HEXA_NS::Elements* hNewElts = _hexaDocument->makeScale( hElts, hVex, k );
1377 if ( BadElement(hNewElts) ) return iElts;
1379 updateData(); //CS_TODO more or less?
1380 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1381 _elementsDirItem->appendRow(eltsItem);
1382 iElts = eltsItem->index();
1389 QModelIndex DocumentModel::makeRotation( const QModelIndex& ielts,
1390 const QModelIndex& iv,
1391 const QModelIndex& ivec, double angle )
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);
1399 HEXA_NS::Elements* hNewElts = _hexaDocument->makeRotation( hElts, hVex, hVec, angle );
1400 if ( BadElement(hNewElts) ) return iElts;
1402 updateData(); //CS_TODO more or less?
1403 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1404 _elementsDirItem->appendRow(eltsItem);
1405 iElts = eltsItem->index();
1411 QModelIndex DocumentModel::makeSymmetryPoint( const QModelIndex& ielts, const QModelIndex& iv )
1415 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1416 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1418 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryPoint (hElts, hVex);
1419 if ( BadElement(hNewElts) ) return iElts;
1421 updateData(); //CS_TODO more or less?
1422 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1423 _elementsDirItem->appendRow(eltsItem);
1424 iElts = eltsItem->index();
1430 QModelIndex DocumentModel::makeSymmetryLine( const QModelIndex& ielts,
1431 const QModelIndex& iv,
1432 const QModelIndex& ivec )
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);
1441 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryLine( hElts, hVex, hVec );
1442 if ( BadElement(hNewElts) ) return iElts;
1444 updateData(); //CS_TODO more or less?
1445 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1446 _elementsDirItem->appendRow(eltsItem);
1447 iElts = eltsItem->index();
1453 QModelIndex DocumentModel::makeSymmetryPlane( const QModelIndex& ielts, const QModelIndex& iv, const QModelIndex& ivec )
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);
1461 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryPlane( hElts, hVex, hVec );
1462 if ( BadElement(hNewElts) ) return iElts;
1464 updateData(); //CS_TODO more or less?
1465 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1466 _elementsDirItem->appendRow(eltsItem);
1467 iElts = eltsItem->index();
1473 bool DocumentModel::performTranslation( const QModelIndex& ielts, const QModelIndex& ivec )
1475 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1476 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1478 int r = _hexaDocument->performTranslation (hElts, hVec);
1479 if ( r == HOK ){ //Job well done?
1489 bool DocumentModel::performScale( const QModelIndex& ielts, const QModelIndex& ivex, double k )
1491 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1492 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1494 int r = _hexaDocument->performScale (hElts, hVex, k);
1504 bool DocumentModel::performRotation( const QModelIndex& ielts, const QModelIndex& ivex, const QModelIndex& ivec, double angle )
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);
1510 int r = _hexaDocument-> performRotation( hElts, hVex, hVec, angle );
1521 bool DocumentModel::performSymmetryPoint( const QModelIndex& ielts, const QModelIndex& ivex )
1523 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1524 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1526 int r = _hexaDocument->performSymmetryPoint( hElts, hVex );
1536 bool DocumentModel::performSymmetryLine( const QModelIndex& ielts, const QModelIndex& ivex, const QModelIndex& ivec )
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);
1542 int r = _hexaDocument->performSymmetryLine( hElts, hVex, hVec );
1552 bool DocumentModel::performSymmetryPlane( const QModelIndex& ielts,
1553 const QModelIndex& ivex,
1554 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->performSymmetryPlane( hElts, hVex, hVec );
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 )
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);
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 );
1590 HEXA_NS::Elements* helts = _hexaDocument->replace( hquads,
1591 hp1, hc1, hp2, hc2, hp3, hc3 );
1592 if ( BadElement(helts) ) return ielts;
1595 ElementsItem* eltsItem = new ElementsItem(helts);
1596 _elementsDirItem->appendRow(eltsItem);
1597 ielts = eltsItem->index();
1602 QModelIndex DocumentModel::getGeomModelIndex(QString& id) const
1605 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
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));
1622 QMultiMap< QString, int > DocumentModel::getAssocShapesIds(const QModelIndex& dataIndex)
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;
1632 PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
1633 QModelIndexList assocsInd = pdsm->getGeomAssociations(dataIndex);
1634 foreach( const QModelIndex& anAssoc, assocsInd )
1636 node = getHexaPtr<HEXA_NS::VertexShape*>(anAssoc);
1637 line = getHexaPtr<HEXA_NS::EdgeShape*>(anAssoc);
1638 face = getHexaPtr<HEXA_NS::FaceShape*>(anAssoc);
1642 mainShape = node->getParentShape();
1643 if (mainShape != NULL)
1645 shapeName = mainShape->getName();
1646 subid = node->getIdent();
1649 else if (line != NULL)
1651 mainShape = line->getParentShape();
1652 if (mainShape != NULL)
1654 shapeName = mainShape->getName();
1655 subid = line->getIdent();
1658 else if (face != NULL)
1660 mainShape = face->getParentShape();
1661 if (mainShape != NULL)
1663 shapeName = mainShape->getName();
1664 subid = face->getIdent();
1668 if (!shapeName.isEmpty())
1669 result.insert( shapeName, subid );
1671 shapeName = QString();
1676 bool DocumentModel::setVertexAssociation( const QModelIndex& iVertex, double x, double y, double z)
1678 HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex *>(iVertex);
1680 if (vertex == NULL || _hexaDocument == NULL || vertex->setAssociation(x, y, z) != HOK)
1683 HEXA_NS::VertexShape* assoc = vertex->getAssociation();
1686 HEXA_NS::NewShape* mainSh = assoc->getParentShape();
1687 setData( iVertex, QVariant::fromValue(QString(mainSh->getName())+","+QString::number(assoc->getIdent())+";"), HEXA_ASSOC_ENTRY_ROLE );
1693 bool DocumentModel::setVertexAssociation( const QModelIndex& iVertex, const QModelIndex& iGeomVertex)
1695 //parameters control
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;
1704 if (vertex->setAssociation(geomVertex) != HOK)
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 );
1714 bool DocumentModel::addEdgeAssociation( const QModelIndex& iEdge, const QModelIndex& iGeomEdge, double start, double end)
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;
1725 //add association in the engine side
1726 if (edge->addAssociation(geomEdge, start, end) != HOK)
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;
1734 setData( iEdge, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1740 bool DocumentModel::addQuadAssociation (const QModelIndex& iQuad, const QModelIndex& iGeomFace)
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)
1748 HEXA_NS::NewShape* mainShape = geomFace->getParentShape();
1749 if (mainShape == NULL) return false;
1752 if (quad->addAssociation(geomFace) != HOK)
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 );
1765 QModelIndex DocumentModel::getVertexAssociation(const QModelIndex& iVertex)
1767 HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1769 return QModelIndex();
1771 //get the associated geom vertex
1772 HEXA_NS::VertexShape* geomVertex = vertex->getAssociation();
1773 if (geomVertex == NULL)
1774 return QModelIndex();
1776 //convert geom vertex to qmodelindex
1777 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1779 return QModelIndex();
1781 return pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(geomVertex));
1785 QModelIndexList DocumentModel::getEdgeAssociations(const QModelIndex& iEdge)
1787 QModelIndexList result;
1788 HEXA_NS::Edge* edge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
1789 if (edge == NULL) return result;
1791 HEXA_NS::EdgeShape* geomEdge;
1792 HEXA_NS::AssoEdge* anEdgeAssoc;
1794 PatternGeomSelectionModel* pGSModel = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1795 int nbAssocs = edge->countAssociation();
1796 for (int i = 0; i < nbAssocs; ++i)
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));
1809 QModelIndexList DocumentModel::getQuadAssociations(const QModelIndex& iQuad)
1811 QModelIndexList result;
1812 QModelIndex geomQuadIndex;
1813 HEXA_NS::Quad* quad = getHexaPtr<HEXA_NS::Quad*>(iQuad);
1814 if (quad == NULL) return result;
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;
1821 HEXA_NS::FaceShape* geomFace;
1823 int nbAssocs = quad->countAssociation();
1824 for (int i = 0; i < nbAssocs; ++i)
1826 geomFace = quad->getAssociation(i);
1827 if (geomFace == NULL) continue;
1829 geomQuadIndex = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomFace) );
1830 result << geomQuadIndex;
1837 bool DocumentModel::associateOpenedLine( const QModelIndexList& iedges,
1838 HEXA_NS::NewShapes shapes,
1839 HEXA_NS::IntVector subIds,
1844 HEXA_NS::Edges mline;
1846 HEXA_NS::Edge* hedge = NULL;
1847 foreach( const QModelIndex& iedge, iedges ){
1848 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1850 mline.push_back( hedge );
1853 int err = _hexaDocument->associateOpenedLine( mline, shapes, subIds, pstart, pend );
1861 bool DocumentModel::associateClosedLine( const QModelIndex& ivertex,
1862 const QModelIndexList& iedges,
1863 HEXA_NS::NewShapes shapes,
1864 HEXA_NS::IntVector subIds,
1868 HEXA_NS::Vertex* mfirst = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1869 HEXA_NS::Edges mline;
1871 HEXA_NS::Edge* hedge = NULL;
1872 foreach( const QModelIndex& iedge, iedges ){
1873 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1875 mline.push_back( hedge );
1878 int err = _hexaDocument->associateClosedLine( mfirst, mline, shapes, subIds, pstart, inv);
1886 // ************ GROUPS ************
1888 QModelIndex DocumentModel::addGroup( const QString& name, Group kind )
1892 HEXA_NS::Group* hGroup = _hexaDocument->addGroup( name.toLocal8Bit().constData(), kind );
1893 if ( hGroup == NULL ) return iGroup;
1895 GroupItem* groupItem = new GroupItem(hGroup);
1896 groupItem->setData( _entry, HEXA_DOC_ENTRY_ROLE );
1897 _groupDirItem->appendRow(groupItem);
1898 iGroup = groupItem->index();
1904 bool DocumentModel::removeGroup( const QModelIndex& igrp )
1906 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1907 int r = _hexaDocument->removeGroup ( hGroup );
1910 removeRow( igrp.row(), igrp.parent());
1918 QModelIndexList DocumentModel::getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const
1920 QModelIndexList iElements;
1922 HEXA_NS::Group* g = iGroup.data(HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1923 if ( g == NULL ) return iElements;
1925 QModelIndexList iFound;
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();
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;
1938 iFound = match( index(0, 0),
1942 Qt::MatchRecursive );
1943 if ( !iFound.isEmpty() )
1944 iElements << iFound[0];
1949 // 7.4 Boite: éditer un groupe
1950 void DocumentModel::setGroupName( const QModelIndex& igrp, const QString& name )
1952 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1955 hGroup->setName( name.toLocal8Bit().constData() );
1956 setData(igrp, QVariant::fromValue( name ) );
1960 bool DocumentModel::addGroupElement( const QModelIndex& igrp, const QModelIndex& ielt )
1962 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1963 if (hGroup == NULL) return false;
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;
1975 res = hGroup->addElement( hElt );
1977 if ( res == HOK ) return true;
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;
1987 if (hGroup->removeElement( nro ) == HOK) return true;
1992 bool DocumentModel::clearGroupElement( const QModelIndex& igrp )
1994 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
1996 if ( hGroup != NULL)
1998 hGroup->clearElement();
2004 // ************ LAWS ************
2007 QModelIndex DocumentModel::addLaw( const QString& name, int nbnodes )
2011 HEXA_NS::Law* hLaw = _hexaDocument->addLaw( name.toLocal8Bit().constData(), nbnodes );
2012 if ( BadElement(hLaw) ) return iLaw;
2014 LawItem* lawItem = new LawItem(hLaw);
2015 _lawDirItem->appendRow(lawItem);
2016 iLaw = lawItem->index();
2021 bool DocumentModel::setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type )
2025 HEXA_NS::Law* hLaw = data(ilaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2029 ok = hLaw->setNodes( nbnodes );
2030 ( ok == HOK) ? ret = true : ret = false;
2031 ok = hLaw->setCoefficient( coeff );
2032 hLaw->setKind(type);
2039 bool DocumentModel::removeLaw( const QModelIndex& ilaw )
2041 HEXA_NS::Law* hLaw = data(ilaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2042 int r = _hexaDocument->removeLaw( hLaw );
2045 removeRow( ilaw.row(), ilaw.parent());
2052 bool DocumentModel::setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way )
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 *>();
2057 int r = hPropagation->setLaw( hLaw );
2058 hPropagation->setWay( way );
2060 if ( r == HOK ) return true;
2066 QModelIndexList DocumentModel::getPropagation( const QModelIndex& iPropagation ) const
2068 QModelIndexList iEdges;
2070 QModelIndexList iFound;
2071 HEXA_NS::Propagation* propa = iPropagation.data(HEXA_DATA_ROLE).value<HEXA_NS::Propagation *>();
2072 if ( propa == NULL ) return iEdges;
2074 const HEXA_NS::Edges& edges = propa->getEdges();
2075 for ( HEXA_NS::Edges::const_iterator anEdge = edges.begin(), endIt = edges.end();
2078 iFound = match( index(0, 0),
2080 QVariant::fromValue( *anEdge ),
2082 Qt::MatchRecursive);
2083 if ( !iFound.isEmpty() )
2084 iEdges << iFound[0];
2090 HEXA_NS::Document* DocumentModel::documentImpl()
2092 return _hexaDocument;
2095 QString DocumentModel::documentEntry()
2100 // 8.3 Boite: éditer une loi CS_TODO
2103 /*****************************************************************
2105 *****************************************************************/
2107 PatternDataModel::PatternDataModel( QObject * parent ) :
2108 QSortFilterProxyModel( parent )
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);
2114 setFilterRole(HEXA_TREE_ROLE);
2115 setFilterRegExp ( QRegExp(dataRegExp) );
2118 // *** Pour suppression des panneaux "Builder" et "Geometry" ****/
2120 //PatternDataModel::PatternDataModel( QObject * parent ) :
2121 // QSortFilterProxyModel( parent )
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);
2133 // setFilterRole(HEXA_TREE_ROLE);
2134 // setFilterRegExp ( QRegExp(dataRegExp) );
2139 PatternDataModel::~PatternDataModel()
2143 HEXA_NS::Document* PatternDataModel::documentImpl()
2145 HEXA_NS::Document* doc = NULL;
2146 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2147 if (m) doc = m->documentImpl();
2151 QString PatternDataModel::documentEntry()
2154 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2155 if (m) entry = m->documentEntry();
2159 Qt::ItemFlags PatternDataModel::flags(const QModelIndex &index) const
2161 Qt::ItemFlags flags;
2163 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2165 flags = m->flags( mapToSource(index) );
2171 QVariant PatternDataModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2173 if ( section == 0 and orientation == Qt::Horizontal and role == Qt::DisplayRole ){
2174 return QVariant( "Data" );
2176 return QSortFilterProxyModel::headerData ( section, orientation, role );
2181 QStandardItem* PatternDataModel::itemFromIndex ( const QModelIndex & index ) const
2183 QStandardItem *item = NULL;
2184 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2186 item = m->itemFromIndex( mapToSource(index) );
2191 PatternBuilderModel::PatternBuilderModel( QObject * parent ) :
2192 QSortFilterProxyModel( parent )
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);
2198 setFilterRole( HEXA_TREE_ROLE );
2199 setFilterRegExp ( QRegExp( builderRegExp ) );
2202 PatternBuilderModel::~PatternBuilderModel()
2206 Qt::ItemFlags PatternBuilderModel::flags(const QModelIndex &index) const
2208 Qt::ItemFlags flags;
2210 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2212 flags = m->flags( mapToSource(index) );
2217 QVariant PatternBuilderModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2219 if ( section == 0 and orientation == Qt::Horizontal and role == Qt::DisplayRole ){
2220 return QVariant( "Builder" );
2222 return QSortFilterProxyModel::headerData ( section, orientation, role );
2226 QStandardItem* PatternBuilderModel::itemFromIndex ( const QModelIndex & index ) const
2228 QStandardItem *item = NULL;
2229 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2231 item = m->itemFromIndex( mapToSource(index) );
2236 //====================================================================
2238 //====================================================================
2239 PatternGeomModel::PatternGeomModel( QObject * parent ) :
2240 QSortFilterProxyModel( parent )
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);
2248 setFilterRole( HEXA_TREE_ROLE );
2249 setFilterRegExp ( QRegExp(builderRegExp ) );
2252 PatternGeomModel::~PatternGeomModel()
2256 Qt::ItemFlags PatternGeomModel::flags(const QModelIndex &index) const
2258 Qt::ItemFlags flags;
2260 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2262 flags = m->flags( mapToSource(index) );
2267 QVariant PatternGeomModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2269 if ( section == 0 and orientation == Qt::Horizontal and role == Qt::DisplayRole ){
2270 return QVariant( "Geometry" );
2272 return QSortFilterProxyModel::headerData ( section, orientation, role );
2276 QStandardItem* PatternGeomModel::itemFromIndex ( const QModelIndex & index ) const
2278 QStandardItem *item = NULL;
2279 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2281 item = m->itemFromIndex( mapToSource(index) );
2285 //==============================================================
2288 AssociationsModel::AssociationsModel( QObject * parent ) :
2289 QSortFilterProxyModel( parent )
2291 QString assocRegExp;
2293 setFilterRole( HEXA_TREE_ROLE );
2294 setFilterRegExp ( QRegExp(assocRegExp) );
2297 AssociationsModel::~AssociationsModel()
2301 Qt::ItemFlags AssociationsModel::flags(const QModelIndex &index) const
2303 Qt::ItemFlags flags;
2305 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2307 flags = m->flags( mapToSource(index) );
2312 QVariant AssociationsModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2314 if ( section == 0 and orientation == Qt::Horizontal and role == Qt::DisplayRole ){
2315 return QVariant( "Associations" );
2317 return QSortFilterProxyModel::headerData ( section, orientation, role );
2321 QStandardItem* AssociationsModel::itemFromIndex ( const QModelIndex & index ) const
2323 QStandardItem *item = NULL;
2324 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2326 item = m->itemFromIndex( mapToSource(index) );
2331 GroupsModel::GroupsModel( QObject * parent ) :
2332 QSortFilterProxyModel( parent )
2334 QString groupsRegExp =QString("(%1|%2)").arg(GROUP_TREE).arg(GROUP_DIR_TREE);
2336 setFilterRole( HEXA_TREE_ROLE );
2337 setFilterRegExp ( QRegExp(groupsRegExp ) );
2340 GroupsModel::~GroupsModel()
2344 Qt::ItemFlags GroupsModel::flags(const QModelIndex &index) const
2346 Qt::ItemFlags flags;
2348 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2350 flags = m->flags( mapToSource(index) );
2355 QVariant GroupsModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2357 if ( section == 0 and orientation == Qt::Horizontal and role == Qt::DisplayRole ){
2358 return QVariant( "Groups" );
2360 return QSortFilterProxyModel::headerData ( section, orientation, role );
2364 QStandardItem* GroupsModel::itemFromIndex ( const QModelIndex & index ) const
2366 QStandardItem *item = NULL;
2367 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2369 item = m->itemFromIndex( mapToSource(index) );
2374 QModelIndexList GroupsModel::getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const
2376 QModelIndexList elements;
2377 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2379 elements = m->getGroupElements( mapToSource(iGroup), kind );
2384 MeshModel::MeshModel( QObject * parent ) :
2385 QSortFilterProxyModel( parent )
2387 QString meshRegExp =QString("(%1|%2|%3|%4)").arg(LAW_TREE).arg(LAW_DIR_TREE) .arg(PROPAGATION_TREE).arg(PROPAGATION_DIR_TREE);
2389 setFilterRole( HEXA_TREE_ROLE );
2390 setFilterRegExp ( QRegExp(meshRegExp) );
2393 MeshModel::~MeshModel()
2397 Qt::ItemFlags MeshModel::flags(const QModelIndex &index) const
2399 Qt::ItemFlags flags;
2401 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2403 flags = m->flags( mapToSource(index) );
2408 QVariant MeshModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2410 if ( section == 0 and orientation == Qt::Horizontal and role == Qt::DisplayRole ){
2411 return QVariant( "Mesh" );
2413 return QSortFilterProxyModel::headerData ( section, orientation, role );
2417 QStandardItem* MeshModel::itemFromIndex ( const QModelIndex & index ) const
2419 QStandardItem *item = NULL;
2420 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2422 item = m->itemFromIndex( mapToSource(index) );
2427 QModelIndexList MeshModel::getPropagation( const QModelIndex& iPropagation ) const
2429 QModelIndexList edges;
2430 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2432 edges = m->getPropagation( mapToSource(iPropagation) );
2438 // ================================== NEW ======================================
2440 // ===== CARTESIAN GRID
2442 QModelIndex DocumentModel::makeCartesianTop(int nx, int ny, int nz)
2446 HEXA_NS::Elements* helts = _hexaDocument->makeCartesianTop( nx, ny, nz );
2447 if ( BadElement(helts) )
2450 result = addElementsToTree(helts, _elementsDirItem);
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)
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);
2466 HEXA_NS::Elements* helts = _hexaDocument->makeCartesianUni( hcenter, hbase, hvec, haxis,
2467 lx, ly, lz, nx, ny, nz);
2468 if ( BadElement(helts) )
2471 result = addElementsToTree(helts, _elementsDirItem);
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)
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);
2487 HEXA_NS::Elements* helts = _hexaDocument->makeCartesian( hcenter, hbase, hvec, haxis,
2488 radius, angles, heights);
2489 if ( BadElement(helts) )
2492 result = addElementsToTree(helts, _elementsDirItem);
2500 QModelIndex DocumentModel::makeSphereTop (int nr, int na, int nh)
2504 HEXA_NS::Elements* helts = _hexaDocument->makeSphereTop( nr, na, nh );
2505 if ( BadElement(helts) )
2508 result = addElementsToTree(helts, _elementsDirItem);
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)
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);
2526 HEXA_NS::Elements* helts = _hexaDocument->makeSphereUni( hcenter, hvec_x, hvec_z,
2527 rtrou, rext, ang, hvplan,
2529 result = addElementsToTree(helts, _elementsDirItem);
2534 QModelIndex DocumentModel::makeSphere (QModelIndex& icenter,
2535 QModelIndex& ivec_x, QModelIndex& ivec_z,
2536 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
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);
2544 HEXA_NS::Elements* helts = _hexaDocument->makeSphere( hcenter, hvec_x, hvec_z,
2547 result = addElementsToTree(helts, _elementsDirItem);
2554 QModelIndex DocumentModel::makeSphericalTop (int nbre, int crit)
2558 HEXA_NS::Elements* helts = _hexaDocument->makeSphericalTop(nbre, crit);
2559 if (BadElement(helts))
2562 result = addElementsToTree(helts, _elementsDirItem);
2567 QModelIndex DocumentModel::makeSphericalUni (QModelIndex& icenter,
2568 QModelIndex& ivec_x, QModelIndex& ivec_z,
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);
2578 HEXA_NS::Elements* helts = _hexaDocument->makeSphericalUni(hcenter, hvec_x, hvec_z, rayon, nbre, crit);
2579 if (BadElement(helts))
2582 result = addElementsToTree(helts, _elementsDirItem);
2587 QModelIndex DocumentModel::makeSpherical (QModelIndex& icenter,
2588 QModelIndex& ivec_x, QModelIndex& ivec_z,
2589 vector<double>& rayon,
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);
2598 HEXA_NS::Elements* helts = _hexaDocument->makeSpherical(hcenter, hvec_x, hvec_z, rayon, crit);
2599 if (BadElement(helts))
2602 result = addElementsToTree(helts, _elementsDirItem);
2608 QModelIndex DocumentModel::makeRindTop (int nr, int na, int nh)
2612 HEXA_NS::Elements* helts = _hexaDocument->makeRindTop(nr, na, nh);
2613 if (BadElement(helts))
2616 result = addElementsToTree(helts, _elementsDirItem);
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)
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);
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))
2639 result = addElementsToTree(helts, _elementsDirItem);
2644 QModelIndex DocumentModel::makeRind (QModelIndex& icenter,
2645 QModelIndex& ivec_x, QModelIndex& ivec_z,
2646 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
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);
2654 HEXA_NS::Elements* helts = _hexaDocument->makeRind(hcenter, hvec_x, hvec_z, tray, tang, thaut);
2655 if (BadElement(helts))
2658 result = addElementsToTree(helts, _elementsDirItem);
2663 // ======== Cylinder
2664 QModelIndex DocumentModel::makeCylinderTop(int nr, int na, int nh)
2668 HEXA_NS::Elements* helts = _hexaDocument->makeCylinderTop(nr, na, nh);
2669 if (BadElement(helts))
2672 result = addElementsToTree(helts, _elementsDirItem);
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)
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);
2687 HEXA_NS::Elements* helts = _hexaDocument->makeCylinderUni(horig, hvecx, hvecz,
2688 rint, rext, angle, haut,
2690 if (BadElement(helts))
2693 result = addElementsToTree(helts, _elementsDirItem);
2698 QModelIndex DocumentModel::makeCylinder(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2699 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
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);
2707 HEXA_NS::Elements* helts = _hexaDocument->makeCylinder(horig, hvecx, hvecz, tray, tang, thaut);
2708 if (BadElement(helts))
2711 result = addElementsToTree(helts, _elementsDirItem);
2717 // ======== Cylinders
2718 QModelIndex DocumentModel::makeCylinders(QModelIndex& iorig1, QModelIndex& ivecz1, double r1, double h1,
2719 QModelIndex& iorig2, QModelIndex& ivecz2, double r2, double h2)
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);
2728 HEXA_NS::BiCylinder* helts = _hexaDocument->makeCylinders(horig1, hvecz1, r1, h1,
2729 horig2, hvecz2, r2, h2);
2730 if (BadElement(helts))
2733 result = addElementsToTree(helts, _crossElementsDirItem);
2739 QModelIndex DocumentModel::makePipeTop(int nr, int na, int nh)
2743 HEXA_NS::Elements* helts = _hexaDocument->makePipeTop(nr, na, nh);
2744 if (BadElement(helts))
2747 result = addElementsToTree(helts, _elementsDirItem);
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)
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);
2762 HEXA_NS::Elements* helts = _hexaDocument->makePipeUni(horig, hvecx, hvecz, rint, rext, angle,
2764 if (BadElement(helts))
2767 result = addElementsToTree(helts, _elementsDirItem);
2772 QModelIndex DocumentModel::makePipe(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2773 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
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);
2781 HEXA_NS::Elements* helts = _hexaDocument->makePipe(horig, hvecx, hvecz, tray, tang, thaut);
2782 if (BadElement(helts))
2785 result = addElementsToTree(helts, _elementsDirItem);
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)
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);
2801 HEXA_NS::BiCylinder* helts = _hexaDocument->makePipes(horig1, hvecz1, rint1, rex1, h1,
2802 horig2, hvecz2, rint2, rex2, h2);
2803 if (BadElement(helts))
2806 result = addElementsToTree(helts, _crossElementsDirItem);
2811 // ======== Join Quads
2812 QModelIndex DocumentModel::joinQuadUni(QModelIndex& istart, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
2813 QModelIndex& iv3, QModelIndex& iv4, int nb)
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);
2824 HEXA_NS::Elements* helts = _hexaDocument->joinQuadUni(hstart, hdest, hv1, hv2, hv3, hv4, nb);
2825 if (BadElement(helts))
2828 result = addElementsToTree(helts, _elementsDirItem);
2833 QModelIndex DocumentModel::joinQuad(QModelIndex& istart, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
2834 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen)
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);
2845 HEXA_NS::Elements* helts = _hexaDocument->joinQuad(hstart, hdest, hva1, hvb1, hva2, hvb2, tlen);
2846 if (BadElement(helts))
2849 result = addElementsToTree(helts, _elementsDirItem);
2854 QModelIndex DocumentModel::joinQuadsUni(QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
2855 QModelIndex& iv3, QModelIndex& iv4, int nb)
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]));
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);
2870 HEXA_NS::Elements* helts = _hexaDocument->joinQuadsUni(hstarts, hdest, hv1, hv2, hv3, hv4, nb);
2871 if (BadElement(helts))
2874 result = addElementsToTree(helts, _elementsDirItem);
2879 QModelIndex DocumentModel::joinQuads(QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
2880 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen)
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]));
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);
2895 HEXA_NS::Elements* helts = _hexaDocument->joinQuads(hstarts, hdest, hva1, hvb1, hva2, hvb2, tlen);
2896 if (BadElement(helts))
2899 result = addElementsToTree(helts, _elementsDirItem);
2904 // ======== Quad Revolution
2905 QModelIndex DocumentModel::revolutionQuadUni(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
2906 double angle, int nbre)
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);
2914 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuadUni(hstart, hcenter, haxis, angle, nbre);
2915 if (BadElement(helts))
2918 result = addElementsToTree(helts, _elementsDirItem);
2923 QModelIndex DocumentModel::revolutionQuad(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
2924 vector<double>& angles)
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->revolutionQuad(hstart, hcenter, haxis, angles);
2933 if (BadElement(helts))
2936 result = addElementsToTree(helts, _elementsDirItem);
2941 QModelIndex DocumentModel::revolutionQuadsUni(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
2942 double angle, int nbre)
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]));
2951 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2952 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2954 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuadsUni(hstarts, hcenter, haxis, angle, nbre);
2955 if (BadElement(helts))
2958 result = addElementsToTree(helts, _elementsDirItem);
2963 QModelIndex DocumentModel::revolutionQuads(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
2964 vector<double>& angles)
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]));
2973 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2974 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2976 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuads(hstarts, hcenter, haxis, angles);
2977 if (BadElement(helts))
2980 result = addElementsToTree(helts, _elementsDirItem);
2986 // ==== PrismQuad or ExtrudeQuad
2987 QModelIndex DocumentModel::extrudeQuadTop(QModelIndex& istart, int nbre)
2991 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
2992 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadTop(hstart, nbre);
2993 if (BadElement(helts))
2996 result = addElementsToTree(helts, _elementsDirItem);
3001 QModelIndex DocumentModel::extrudeQuadUni(QModelIndex& istart, QModelIndex& dv, double len, int nbre)
3005 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3006 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(dv);
3008 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadUni(hstart, hvec, len, nbre);
3009 if (BadElement(helts))
3012 result = addElementsToTree(helts, _elementsDirItem);
3017 QModelIndex DocumentModel::extrudeQuad(QModelIndex& istart, QModelIndex& dv, vector<double>& tlen)
3021 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3022 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(dv);
3024 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuad(hstart, hvec, tlen);
3025 if (BadElement(helts))
3027 result = addElementsToTree(helts, _elementsDirItem);
3032 QModelIndex DocumentModel::extrudeQuadsTop (QModelIndexList& istarts, int nbre)
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]));
3041 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadsTop(hquads, nbre);
3042 if (BadElement(helts))
3044 result = addElementsToTree(helts, _elementsDirItem);
3049 QModelIndex DocumentModel::extrudeQuadsUni (QModelIndexList& istarts, QModelIndex& axis, double len, int nbre)
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]));
3058 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(axis);
3060 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadsUni(hquads, haxis, len, nbre);
3061 if (BadElement(helts))
3063 result = addElementsToTree(helts, _elementsDirItem);
3068 QModelIndex DocumentModel::extrudeQuads(QModelIndexList& istarts, QModelIndex& iaxis, vector<double>& tlen)
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]));
3077 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3079 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuads(hquads, haxis, tlen);
3080 if (BadElement(helts))
3082 result = addElementsToTree(helts, _elementsDirItem);
3088 QModelIndex DocumentModel::cutUni(QModelIndex& iEdge, int nbre)
3092 HEXA_NS::Edge* hedge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
3094 HEXA_NS::Elements* helts = _hexaDocument->cutUni(hedge, nbre);
3095 if (BadElement(helts))
3097 result = addElementsToTree(helts, _elementsDirItem);
3102 QModelIndex DocumentModel::cut(QModelIndex& iEdge, vector<double>& tlen)
3106 HEXA_NS::Edge* hedge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
3108 HEXA_NS::Elements* helts = _hexaDocument->cut(hedge, tlen);
3109 if (BadElement(helts))
3111 result = addElementsToTree(helts, _elementsDirItem);
3116 // ================================== END NEW ==================================