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"
52 #include <Geom_Circle.hxx>
53 #include <gp_Circ.hxx>
54 #include <BRep_Tool.hxx>
55 #include <TopoDS_Edge.hxx>
60 //using namespace HEXA_NS;
61 using namespace HEXABLOCK::GUI;
63 /*****************************************************************
65 *****************************************************************/
66 // DocumentModel::DocumentModel(QObject * parent):
67 DocumentModel::DocumentModel(HEXA_NS::Document* docIn, const QString& entryIn, QObject * parent):
68 QStandardItemModel(parent),
69 _hexaFile( new QTemporaryFile() ),
70 _hexaDocument( docIn ),
72 // _hexaDocument( new HEXA_NS::Document("/tmp/doc.hex") ), //CS_TODO
74 _vertexDirItem( new QStandardItem(tr("TREE_ITEM_VERTEX")) ),
75 _edgeDirItem( new QStandardItem(tr("TREE_ITEM_EDGE")) ),
76 _quadDirItem( new QStandardItem(tr("TREE_ITEM_QUAD")) ),
77 _hexaDirItem( new QStandardItem(tr("TREE_ITEM_HEXA")) ),
79 _vectorDirItem( new QStandardItem(tr("TREE_ITEM_VECTOR")) ),
80 _elementsDirItem( new QStandardItem(tr("TREE_ITEM_ELEMENT")) ),
81 _crossElementsDirItem( new QStandardItem(tr("TREE_ITEM_CROSSELEMENT")) ),
83 _explicitShapesDirItem( new QStandardItem(tr("TREE_ITEM_EXPSHAPE")) ),
84 _implicitShapesDirItem( new QStandardItem(tr("TREE_ITEM_IMPSHAPE")) ),
85 _cloudOfPointsDirItem( new QStandardItem(tr("TREE_ITEM_CLOUD_OF_POINT")) ),
87 _groupDirItem( new QStandardItem(tr("TREE_ITEM_GROUP")) ),
89 _lawDirItem( new QStandardItem(tr("TREE_ITEM_LAW")) ),
90 _propagationDirItem( new QStandardItem(tr("TREE_ITEM_PROPAGATION")) ),
92 _vertexItemFlags( Qt::NoItemFlags ),
93 _edgeItemFlags( Qt::NoItemFlags ),
94 _quadItemFlags( Qt::NoItemFlags ),
95 _hexaItemFlags( Qt::NoItemFlags ),
96 _vectorItemFlags( Qt::NoItemFlags ),
97 _elementsItemFlags( Qt::NoItemFlags ),
98 _crossElementsItemFlags( Qt::NoItemFlags ),
100 _disallowEdition( false )
102 // setColumnCount( 4 ); //CS_TEST
103 if ( !_hexaDocument && _hexaFile->open() ){
104 _hexaDocument = new HEXA_NS::Document( _hexaFile->fileName().toLatin1() );
105 _hexaDocument->reorderFaces();
108 QStandardItem *parentItem = invisibleRootItem();
109 // parentItem->setData( QString::number( reinterpret_cast<intptr_t>(_hexaDocument) ), HEXA_ENTRY_ROLE );
110 parentItem->setData( _entry, HEXA_ENTRY_ROLE );
112 _vertexDirItem->setData( VERTEX_DIR_TREE, HEXA_TREE_ROLE );
113 _edgeDirItem->setData( EDGE_DIR_TREE, HEXA_TREE_ROLE );
114 _quadDirItem->setData( QUAD_DIR_TREE, HEXA_TREE_ROLE );
115 _hexaDirItem->setData( HEXA_DIR_TREE, HEXA_TREE_ROLE );
117 _vectorDirItem->setData( VECTOR_DIR_TREE, HEXA_TREE_ROLE );
118 _elementsDirItem->setData( ELEMENTS_DIR_TREE, HEXA_TREE_ROLE );
119 _crossElementsDirItem->setData( CROSSELEMENTS_DIR_TREE, HEXA_TREE_ROLE );
121 _explicitShapesDirItem->setData( EXPLICIT_SHAPES_DIR_TREE, HEXA_TREE_ROLE );
122 _implicitShapesDirItem->setData( IMPLICIT_SHAPES_DIR_TREE, HEXA_TREE_ROLE );
123 _cloudOfPointsDirItem->setData( CLOUD_OF_POINTS_DIR_TREE, HEXA_TREE_ROLE );
125 _groupDirItem->setData( GROUP_DIR_TREE, HEXA_TREE_ROLE );
127 //CS_TODO associations
129 _lawDirItem->setData( LAW_DIR_TREE, HEXA_TREE_ROLE );
130 _propagationDirItem->setData( PROPAGATION_DIR_TREE, HEXA_TREE_ROLE );
132 parentItem->appendRow(_vertexDirItem);
133 parentItem->appendRow(_edgeDirItem);
134 parentItem->appendRow(_quadDirItem);
135 parentItem->appendRow(_hexaDirItem);
137 parentItem->appendRow(_vectorDirItem);
138 parentItem->appendRow(_elementsDirItem);
139 parentItem->appendRow(_crossElementsDirItem);
141 parentItem->appendRow(_explicitShapesDirItem);
142 parentItem->appendRow(_implicitShapesDirItem);
144 parentItem->appendRow(_groupDirItem);
145 parentItem->appendRow(_lawDirItem);
146 parentItem->appendRow(_propagationDirItem);
149 DocumentModel::~DocumentModel()
151 if (_hexaDocument != NULL)
152 delete _hexaDocument;
154 if (_hexaFile != NULL)
158 void DocumentModel::setName(const QString& name)
160 _hexaDocument->setName( name.toLocal8Bit().constData() );
161 emit nameChanged(QString(_hexaDocument->getName()));
164 HEXA_NS::EltBase* DocumentModel::getHexaPtr(const QModelIndex& iElt)
166 HEXA_NS::EltBase *elt = NULL;
167 switch ( /*data(iElt, HEXA_TREE_ROLE).toInt()*/iElt.data(HEXA_TREE_ROLE).toInt() ){
168 case VERTEX_TREE : elt = getHexaPtr<HEXA_NS::Vertex*>(iElt); break;
169 case EDGE_TREE : elt = getHexaPtr<HEXA_NS::Edge*>(iElt); break;
170 case QUAD_TREE : elt = getHexaPtr<HEXA_NS::Quad*>(iElt); break;
171 case HEXA_TREE : elt = getHexaPtr<HEXA_NS::Hexa*>(iElt); break;
172 case VECTOR_TREE : elt = getHexaPtr<HEXA_NS::Vector*>(iElt); break;
173 case ELEMENTS_TREE : elt = getHexaPtr<HEXA_NS::Elements*>(iElt); break;
174 // case CROSSELEMENTS_TREE : elt = getHexaPtr<HEXA_NS::CrossElements*>(iElt); break;
175 case GEOMSHAPE_TREE: elt = getHexaPtr<HEXA_NS::NewShape*>(iElt); break;
176 case GEOMPOINT_TREE: elt = getHexaPtr<HEXA_NS::VertexShape*>(iElt); break;
177 case GEOMEDGE_TREE: elt = getHexaPtr<HEXA_NS::EdgeShape*>(iElt); break;
178 case GEOMFACE_TREE: elt = getHexaPtr<HEXA_NS::FaceShape*>(iElt); break;
183 //get the number of elements of type 'eltType' in the document
184 int DocumentModel::getNbrElt(HEXA_NS::EnumElt eltType)
186 if (_hexaDocument == NULL) return 0;
188 return _hexaDocument->getNbrElt(eltType);
191 //get the number of elements of type 'eltType' used in the document
192 int DocumentModel::getNbrUsedElt(HEXA_NS::EnumElt eltType)
194 if (_hexaDocument == NULL) return 0;
197 case HEXA_NS::EL_VERTEX:
198 return _hexaDocument->countUsedVertex();
199 case HEXA_NS::EL_EDGE:
200 return _hexaDocument->countUsedEdge();
201 case HEXA_NS::EL_QUAD:
202 return _hexaDocument->countUsedQuad();
203 case HEXA_NS::EL_HEXA:
204 return _hexaDocument->countUsedHexa();
209 //associate a shape to the current document
210 bool DocumentModel::addShape(TopoDS_Shape& aShape, QString& name, bool publish)
212 if (aShape.IsNull() || name.isEmpty())
214 bool ok = (_hexaDocument != NULL ? _hexaDocument->addShape(aShape, name.toStdString().c_str()) != NULL : false);
216 // * publish the shape in the study
219 HEXABLOCKGUI* module = HEXABLOCKGUI::getInstance();
222 QMap<QString, TopoDS_Shape> topo_shapes;
223 topo_shapes[name] = aShape;
224 module->addInStudy(topo_shapes, docShapesEntry, docShapesName);
235 //get the number of unused elements of type 'eltType' in the document
236 int DocumentModel::getNbrUnusedElt(HEXA_NS::EnumElt eltType)
238 if (_hexaDocument == NULL)
241 return getNbrElt(eltType) - getNbrUsedElt(eltType);
244 // compute the length of the given edge
245 double DocumentModel::getLength(const QModelIndex& iEdge)
247 // * Get the pointer to the edge
248 HEXA_NS::Edge* edge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
249 HEXA_NS::EdgeShape* geomEdge = getHexaPtr<HEXA_NS::EdgeShape*>(iEdge);
251 // * The edge can be from VTK or OCC View
253 return edge->getLength();
254 else if (geomEdge != NULL)
255 return geomEdge->getLength();
260 // Compute the radius of the given edge
261 double DocumentModel::getRadius(const QModelIndex& iEdge)
263 // * Get the pointer to the edge
264 // * In our case only an OCC edge can have a radius
265 HEXA_NS::EdgeShape* edge = getHexaPtr<HEXA_NS::EdgeShape*>(iEdge);
269 return edge->getRadius();
272 // Compute the angle of the given edge (internal angle)
273 double DocumentModel::getAngle(const QModelIndex& iEdge)
275 // * Get the pointer to the edge
276 HEXA_NS::EdgeShape* edge = getHexaPtr<HEXA_NS::EdgeShape*>(iEdge);
280 return edge->getAngle();
283 //Load the current Document
284 void DocumentModel::load()
286 if (_hexaDocument == NULL)
289 load(_hexaDocument->getName());
293 void DocumentModel::load( const QString& xmlFileName ) // Fill Data
295 _hexaDocument->loadXml(xmlFileName.toLocal8Bit().constData() );
305 emit patternDataChanged();
308 bool DocumentModel::isEmpty() const
310 if (_hexaDocument == NULL) return true;
311 return _hexaDocument->isEmpty();
314 void DocumentModel::save( const QString& xmlFileName )
316 _hexaDocument->save( xmlFileName.toLocal8Bit().constData() );
319 QString DocumentModel::getName()
321 return _hexaDocument->getName();
324 void DocumentModel::updateData()
330 emit patternDataChanged();
333 void DocumentModel::updateGeomTree()
339 QModelIndex DocumentModel::addElementsToTree(HEXA_NS::Elements* helts, QStandardItem* tree)
341 QModelIndex eltIndex;
342 if (helts == NULL || tree == NULL)
346 ElementsItem* eltsItem = new ElementsItem(helts);
347 tree->appendRow(eltsItem);
349 return eltsItem->index();
352 void DocumentModel::refresh()
363 emit patternDataChanged();
366 void DocumentModel::clearAll()
376 void DocumentModel::clearData()
378 _vertexDirItem->removeRows( 0, _vertexDirItem->rowCount() );
379 _edgeDirItem->removeRows(0, _edgeDirItem->rowCount() );
380 _quadDirItem->removeRows(0, _quadDirItem->rowCount() );
381 _hexaDirItem->removeRows(0, _hexaDirItem->rowCount() );
383 _vectorDirItem->removeRows(0, _vectorDirItem->rowCount() );
384 _elementsDirItem->removeRows(0, _elementsDirItem->rowCount() );
385 _crossElementsDirItem->removeRows(0, _crossElementsDirItem->rowCount() );
389 //void DocumentModel::clearBuilder()
391 // _vectorDirItem->removeRows(0, _vectorDirItem->rowCount() );
392 // _elementsDirItem->removeRows(0, _elementsDirItem->rowCount() );
393 // _crossElementsDirItem->removeRows(0, _crossElementsDirItem->rowCount() );
396 void DocumentModel::clearGeometry()
398 _explicitShapesDirItem->removeRows(0, _explicitShapesDirItem->rowCount() );
399 _implicitShapesDirItem->removeRows(0, _implicitShapesDirItem->rowCount() );
400 _cloudOfPointsDirItem->removeRows(0, _cloudOfPointsDirItem->rowCount() );
403 void DocumentModel::clearAssociation()
408 void DocumentModel::clearGroups()
410 _groupDirItem->removeRows(0, _groupDirItem->rowCount() );
413 void DocumentModel::clearMesh()
415 _lawDirItem->removeRows(0, _lawDirItem->rowCount() );
416 _propagationDirItem->removeRows(0, _propagationDirItem->rowCount() );
420 void DocumentModel::fillData()
422 PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
425 pdsm->clearHighlightedItems();
428 HEXA_NS::Vertex *v = NULL;
429 VertexItem *vItem = NULL;
430 int nbVertex = _hexaDocument->countVertex();
431 for ( int i=0; i<nbVertex; ++i ){
432 v = _hexaDocument->getVertex(i);
433 vItem = new VertexItem(v, _entry);
434 _vertexDirItem->appendRow(vItem);
437 HEXA_NS::Edge *e = NULL;
438 EdgeItem *eItem = NULL;
439 int nbEdge = _hexaDocument->countEdge();
440 for ( int i=0; i<nbEdge; ++i ){
441 e = _hexaDocument->getEdge(i);
442 eItem = new EdgeItem(e, _entry);
443 _edgeDirItem->appendRow(eItem);
446 HEXA_NS::Quad *q = NULL;
447 QuadItem *qItem = NULL;
448 int nbQuad = _hexaDocument->countQuad();
449 for ( int i=0; i<nbQuad; ++i ){
450 q = _hexaDocument->getQuad(i);
451 qItem = new QuadItem(q, _entry);
452 _quadDirItem->appendRow(qItem);
455 HEXA_NS::Hexa *h = NULL;
456 HexaItem *hItem = NULL;
457 int nbHexa = _hexaDocument->countHexa();
458 for ( int i=0; i<nbHexa; ++i ){
459 h = _hexaDocument->getHexa(i);
460 hItem = new HexaItem(h, _entry);
461 _hexaDirItem->appendRow(hItem);
464 // +++++ Builder ++++++++++++++++++++++++++++++
466 HEXA_NS::Vector *vec = NULL;
467 VectorItem *vecItem = NULL;
468 int nbVector = _hexaDocument->countVector();
469 for ( int i=0; i<nbVector; ++i ){
470 vec = _hexaDocument->getVector(i);
471 vecItem = new VectorItem(vec);
472 _vectorDirItem->appendRow(vecItem);
475 //******* A VOIR AVEC ALAIN POUR LE REMPLISSAGE DE L'ARBRE ELEMENTS ET CROSSELEMENTS (ByCylinder) *******/
476 //******* OU SONT STOCKES LES ELEMENTS ET LES CROSSELEMENTS DANS LE DOCUMENT? ******/
479 // HEXA_NS::Cylinder *c = NULL;
480 // HEXA_NS::Elements* c = NULL;
481 // CylinderItem *cItem = NULL;
482 // ElementsItem* cItem = NULL;
483 // int nbCylinder = _hexaDocument->countCylinder();
484 // for ( int i=0; i<nbCylinder; ++i ){
485 // c = _hexaDocument->getCylinder(i);
486 // cItem = new CylinderItem(c, _entry);
487 // cItem = new ElementsItem(c, _entry);
488 // _cylinderDirItem->appendRow(cItem);
489 // _elementsDirItem->appendRow(cItem);
493 // HEXA_NS::Pipe *p = NULL;
494 // HEXA_NS::Elements* p = NULL;
495 // PipeItem *pItem = NULL;
496 // ElementsItem* pItem = NULL;
497 // int nbPipe = _hexaDocument->countPipe();
498 // for ( int i=0; i<nbPipe; ++i ){
499 // p = _hexaDocument->getPipe(i);
500 // pItem = new PipeItem(p);
501 // pItem = new ElementsItem(p, _entry);
502 // _pipeDirItem->appendRow(pItem);
503 // _elementsDirItem->appendRow(pItem);
505 //********************************************************************************************************
509 //void DocumentModel::fillBuilder()
511 // HEXA_NS::Vector *v = NULL;
512 // VectorItem *vItem = NULL;
513 // int nbVector = _hexaDocument->countVector();
514 // for ( int i=0; i<nbVector; ++i ){
515 // v = _hexaDocument->getVector(i);
516 // vItem = new VectorItem(v);
517 // _vectorDirItem->appendRow(vItem);
520 // //******* A VOIR AVEC ALAIN POUR LE REMPLISSAGE DE L'ARBRE ELEMENTS ET CROSSELEMENTS (ByCylinder) *******/
521 // //******* OU SONT STOCKES LES ELEMENTS ET LES CROSSELEMENTS DANS LE DOCUMENT? ******/
523 // // _cylinderDirItem
524 //// HEXA_NS::Cylinder *c = NULL;
525 //// HEXA_NS::Elements* c = NULL;
526 //// CylinderItem *cItem = NULL;
527 //// ElementsItem* cItem = NULL;
528 //// int nbCylinder = _hexaDocument->countCylinder();
529 //// for ( int i=0; i<nbCylinder; ++i ){
530 //// c = _hexaDocument->getCylinder(i);
531 //// cItem = new CylinderItem(c, _entry);
532 //// cItem = new ElementsItem(c, _entry);
533 //// _cylinderDirItem->appendRow(cItem);
534 //// _elementsDirItem->appendRow(cItem);
538 //// HEXA_NS::Pipe *p = NULL;
539 //// HEXA_NS::Elements* p = NULL;
540 //// PipeItem *pItem = NULL;
541 //// ElementsItem* pItem = NULL;
542 //// int nbPipe = _hexaDocument->countPipe();
543 //// for ( int i=0; i<nbPipe; ++i ){
544 //// p = _hexaDocument->getPipe(i);
545 //// pItem = new PipeItem(p);
546 //// pItem = new ElementsItem(p, _entry);
547 //// _pipeDirItem->appendRow(pItem);
548 //// _elementsDirItem->appendRow(pItem);
550 // //********************************************************************************************************
553 void DocumentModel::fillGeometry()
555 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
556 if (_hexaDocument == NULL /*|| isEmpty()*/ || pgsm == NULL)
559 HEXA_NS::NewShape* shape;
560 HEXA_NS::VertexShape* node;
561 HEXA_NS::EdgeShape* line;
562 HEXA_NS::FaceShape* face;
563 TopoDS_Compound vertexCompound;
564 BRep_Builder compoundBuilder;
566 // * fill the shape tree
569 pgsm->clearHighlightedItems();
570 QMap<QString, TopoDS_Shape> topo_shapes;
571 int nbShapes = _hexaDocument->countShape();
572 for (int i=0; i < nbShapes; ++i)
574 shape = _hexaDocument->getShape(i);
575 QString shapeName = shape->getName();
576 if (!docShapesEntry.contains(shapeName))
578 if (shape->getOrigin() == HEXA_NS::SH_CLOUD)
580 compoundBuilder.MakeCompound(vertexCompound);
581 topo_shapes[shapeName] = vertexCompound;
584 topo_shapes[shapeName] = shape->getShape();
587 GeomShapeItem* shItem = new GeomShapeItem(shape);
588 if (shape->getOrigin() == HEXA_NS::SH_IMPORT)
590 _explicitShapesDirItem->appendRow(shItem);
593 _implicitShapesDirItem->appendRow(shItem);
595 //add vertices to the tree
596 QStandardItem* geomPointDirItem = NULL;
597 if (shape->getOrigin() != HEXA_NS::SH_CLOUD)
599 geomPointDirItem = new QStandardItem(tr("TREE_ITEM_VERTEX"));
600 geomPointDirItem->setData( GEOMPOINT_DIR_TREE, HEXA_TREE_ROLE );
602 if (geomPointDirItem != NULL)
603 shItem->appendRow(geomPointDirItem);
604 int nbVertexShape = shape->countVertex();
605 for (int j=0; j < nbVertexShape; ++j)
607 node = shape->getVertexShape(j);
608 GeomPointItem* gPointItem = new GeomPointItem(node);
609 if (geomPointDirItem != NULL)
610 geomPointDirItem->appendRow(gPointItem);
612 shItem->appendRow(gPointItem);
613 shapeById[shapeName+","+QString::number(node->getIdent())] = node;
615 // * update the compound of vertices
616 if (shape->getOrigin() == HEXA_NS::SH_CLOUD && !vertexCompound.IsNull())
617 compoundBuilder.Add(topo_shapes[shapeName], node->getShape());
620 if (shape->getOrigin() == HEXA_NS::SH_CLOUD)
621 continue; // * it's a cloud of points, there's no edges and no quads to fill
623 //add edges to the tree
624 QStandardItem* geomEdgeDirItem = new QStandardItem(tr("TREE_ITEM_EDGE"));
625 geomEdgeDirItem->setData( GEOMEDGE_DIR_TREE, HEXA_TREE_ROLE );
626 shItem->appendRow(geomEdgeDirItem);
627 int nbEdgeShape = shape->countEdge();
628 for (int j = 0; j < nbEdgeShape; ++j)
630 line = shape->getEdgeShape(j);
631 GeomEdgeItem* gEdgeItem = new GeomEdgeItem(line);
632 geomEdgeDirItem->appendRow(gEdgeItem);
633 shapeById[shapeName+","+QString::number(line->getIdent())] = line;
636 //add faces to the tree
637 QStandardItem* geomFaceDirItem = new QStandardItem(tr("TREE_ITEM_QUAD"));
638 geomFaceDirItem->setData( GEOMFACE_DIR_TREE, HEXA_TREE_ROLE );
639 shItem->appendRow(geomFaceDirItem);
640 int nbFaceShape = shape->countFace();
641 for (int j = 0; j < nbFaceShape; ++j)
643 face = shape->getFaceShape(j);
644 GeomFaceItem* gFaceItem = new GeomFaceItem(face);
645 geomFaceDirItem->appendRow(gFaceItem);
646 shapeById[shapeName+","+QString::number(face->getIdent())] = face;
650 if (topo_shapes.size() == 0)
654 HEXABLOCKGUI* module = HEXABLOCKGUI::getInstance();
656 module->addInStudy(topo_shapes, docShapesEntry, docShapesName);
659 void DocumentModel::fillAssociation()
663 //------------------------------------------- NEW ITEMS
664 //void DocumentModel::fillGroups()
666 // HEXA_NS::Group *g = NULL;
667 // GroupItem *gItem = NULL;
668 // int nbGroup = _hexaDocument->countGroup();
669 // for ( int i=0; i<nbGroup; ++i ){
670 // g = _hexaDocument->getGroup(i);
671 // gItem = new GroupItem(g, _entry);
672 // _groupDirItem->appendRow(gItem);
676 //void DocumentModel::fillMesh()
678 // HEXA_NS::Law *l = NULL;
679 // LawItem *lItem = NULL;
680 // int nbLaw = _hexaDocument->countLaw();
681 // for ( int i=0; i<nbLaw; ++i ){
682 // l = _hexaDocument->getLaw(i);
683 // lItem = new LawItem(l);
684 // _lawDirItem->appendRow(lItem);
687 // HEXA_NS::Propagation *p = NULL;
688 // PropagationItem *pItem = NULL;
689 // int nbPropagation = _hexaDocument->countPropagation();
690 // for ( int i=0; i<nbPropagation; ++i ){
691 // p = _hexaDocument->getPropagation(i);
692 // pItem = new PropagationItem(p, _entry);
693 // pItem->setText(QString("Propagation%1").arg(i) );
694 // _propagationDirItem->appendRow(pItem);
697 //----------------------------------------------- END NEW ITEMS
699 void DocumentModel::fillGroups()
701 HEXA_NS::Group *g = NULL;
702 GroupItem *gItem = NULL;
703 int nbGroup = _hexaDocument->countGroup();
704 for ( int i=0; i<nbGroup; ++i ){
705 g = _hexaDocument->getGroup(i);
706 //std::cout<<"getGroup => "<< i << std::endl;
707 gItem = new GroupItem(g);
708 gItem->setData( _entry, HEXA_DOC_ENTRY_ROLE );
709 _groupDirItem->appendRow(gItem);
713 void DocumentModel::fillMesh()
716 HEXA_NS::Law *l = NULL;
717 LawItem *lItem = NULL;
718 int nbLaw = _hexaDocument->countLaw();
719 for ( int i=0; i<nbLaw; ++i ){
720 l = _hexaDocument->getLaw(i);
721 lItem = new LawItem(l);
722 _lawDirItem->appendRow(lItem);
725 // _propagationDirItem
726 HEXA_NS::Propagation *p = NULL;
727 PropagationItem *pItem = NULL;
728 int nbPropagation = _hexaDocument->countPropagation();
729 for ( int i=0; i<nbPropagation; ++i ){
730 p = _hexaDocument->getPropagation(i);
731 pItem = new PropagationItem(p);
732 pItem->setText(QString("Propagation%1").arg(i) );
733 pItem->setData( _entry, HEXA_DOC_ENTRY_ROLE );
734 _propagationDirItem->appendRow(pItem);
738 HEXA_NS::Hexa* DocumentModel::getQuadHexa(HEXA_NS::Quad* quad)
741 int nbHexa = _hexaDocument->countHexa();
742 for ( int i=0; i<nbHexa; ++i ){
743 hexa = _hexaDocument->getHexa(i);
744 if (hexa->findQuad(quad) > -1) return hexa;
750 Qt::ItemFlags DocumentModel::flags(const QModelIndex &index) const
754 if (!index.isValid()) return Qt::ItemIsEnabled;
756 if ( _disallowEdition ){
757 return QAbstractItemModel::flags(index) | Qt::ItemFlags( ~Qt::ItemIsEditable );
759 return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
763 void DocumentModel::allowEdition()
765 _disallowEdition = false;
768 void DocumentModel::disallowEdition()
770 _disallowEdition = true;
773 void DocumentModel::allowDataSelectionOnly()
775 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
776 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
777 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
778 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
780 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
781 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
782 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
784 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
785 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
786 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
789 void DocumentModel::allowVertexSelectionOnly()
791 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable);
792 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
793 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
794 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
796 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
797 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
798 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
800 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
801 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
802 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
804 // emit layoutChanged();
807 void DocumentModel::allowEdgeSelectionOnly()
809 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
810 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
811 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
812 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
814 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
815 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
816 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
818 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
819 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
820 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
823 void DocumentModel::allowQuadSelectionOnly()
825 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
826 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
827 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
828 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
830 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
831 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
832 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
834 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
835 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
836 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
839 void DocumentModel::allowHexaSelectionOnly()
841 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
842 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
843 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
844 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
846 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
847 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
848 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
850 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
851 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
852 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
855 void DocumentModel::allowVectorSelectionOnly()
857 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
858 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
859 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
860 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
862 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
863 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
864 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
866 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
867 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
868 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
871 void DocumentModel::allowCylinderSelectionOnly()
873 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
874 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
875 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
876 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
878 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
879 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
880 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
882 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
883 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
884 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
887 void DocumentModel::allowPipeSelectionOnly()
889 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
890 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
891 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
892 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
894 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
895 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
896 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
898 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
899 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
900 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
903 void DocumentModel::allowElementsSelectionOnly()
905 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
906 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
907 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
908 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
910 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
911 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
912 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
914 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
915 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
916 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
919 /**********************************************************
920 void DocumentModel::allowCrossElementsSelectionOnly()
922 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
923 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
924 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
925 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
927 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
928 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
929 _crossElementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
931 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
932 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
933 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
935 ********************************************************** */
937 void DocumentModel::allowLawSelectionOnly()
939 _vertexItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
940 _edgeItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
941 _quadItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
942 _hexaItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
944 _vectorItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
945 _elementsItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
946 _crossElementsItemFlags = Qt::ItemFlags( Qt::ItemIsEnabled );
948 _groupItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
949 _lawItemFlags = Qt::ItemFlags( ~Qt::ItemIsEditable );
950 _propagationItemFlags = Qt::ItemFlags( ~Qt::ItemIsEnabled );
954 void DocumentModel::setName( const QModelIndex& iElt, const QString& name )
956 HEXA_NS::EltBase *elt = NULL;
958 switch ( data(iElt, HEXA_TREE_ROLE).toInt() ){
961 HEXA_NS::Group* grp = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Group* >();
962 grp->setName( name.toLatin1().data() );
967 HEXA_NS::Law* l = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Law* >();
968 l->setName( name.toLatin1().data() );
971 // case PROPAGATION_TREE : elt = iElt.data( HEXA_DATA_ROLE ).value< HEXA_NS::Propagation* >(); break;
972 default: elt = getHexaPtr(iElt);
975 if ( elt != NULL ) elt->setName( name.toStdString() );
976 setData( iElt, name );
980 bool DocumentModel::clearEltAssociations( const QModelIndex& iElt )
983 HEXA_NS::EltBase *elt = getHexaPtr(iElt);
986 elt->clearAssociation();
987 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
994 void DocumentModel::clearAssociation(HEXA_NS::EnumElt& eltType)
996 if (_hexaDocument != NULL)
997 _hexaDocument->clearAssociation(eltType);
1000 HEXA_NS::Vertex* vertex;
1001 HEXA_NS::Edge* edge;
1002 HEXA_NS::Quad* quad;
1005 if (HEXABLOCKGUI::currentDocGView == NULL) return;
1006 PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
1007 PatternDataModel* pdm = HEXABLOCKGUI::currentDocGView->getPatternDataModel();
1008 if (pdsm == NULL || pdm == NULL) return;
1010 //update associations in the model
1011 if (eltType == HEXA_NS::EL_VERTEX)
1013 nbElts = _hexaDocument->countVertex();
1014 for (int i = 0; i < nbElts; ++i)
1016 vertex = _hexaDocument->getVertex(i);
1017 iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(vertex)));
1019 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
1022 else if (eltType == HEXA_NS::EL_EDGE)
1024 nbElts = _hexaDocument->countEdge();
1025 for (int i = 0; i < nbElts; ++i)
1027 edge = _hexaDocument->getEdge(i);
1028 iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(edge)));
1030 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
1033 else if (eltType == HEXA_NS::EL_QUAD)
1035 nbElts = _hexaDocument->countQuad();
1036 for (int i = 0; i < nbElts; ++i)
1038 quad = _hexaDocument->getQuad(i);
1039 iElt = pdm->mapToSource(pdsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(quad)));
1041 setData( iElt, QVariant(), HEXA_ASSOC_ENTRY_ROLE );
1047 QModelIndex DocumentModel::addVertex( double x, double y, double z )
1049 QModelIndex vertexIndex;
1051 HEXA_NS::Vertex* hv = _hexaDocument->addVertex(x, y, z);
1052 if (BadElement(hv)) return vertexIndex;
1054 VertexItem* v = new VertexItem(hv, _entry);
1055 _vertexDirItem->appendRow(v);
1056 vertexIndex = v->index();
1057 emit patternDataChanged();
1062 QModelIndex DocumentModel::addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 )
1064 QModelIndex edgeIndex;
1066 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(i_v0);
1067 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(i_v1);
1069 HEXA_NS::Edge* he = _hexaDocument->addEdge( hv0, hv1 );
1070 if ( BadElement(he) ) return edgeIndex;
1072 EdgeItem* e = new EdgeItem(he, _entry);
1073 _edgeDirItem->appendRow(e);
1074 edgeIndex = e->index();
1075 emit patternDataChanged();
1080 QModelIndex DocumentModel::addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec )
1082 QModelIndex edgeIndex;
1084 HEXA_NS::Vertex* hv = getHexaPtr<HEXA_NS::Vertex*>(i_v);
1085 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(i_vec);
1087 if (hv == NULL || hvec == NULL) return edgeIndex;
1089 HEXA_NS::Edge* he = _hexaDocument->addEdgeVector( hv, hvec );
1090 if ( BadElement(he) ) return edgeIndex;
1092 HEXA_NS::Vertex* hv2 = he->getAval(); //the new vertex resulting from the creation of the edge
1093 if (hv2 == NULL) return edgeIndex;
1095 //ADD the edge in the treeview
1096 EdgeItem* e = new EdgeItem(he, _entry);
1097 _edgeDirItem->appendRow(e);
1098 edgeIndex = e->index();
1100 //The resulting Vertex
1101 VertexItem* v = new VertexItem(hv2, _entry);
1102 _vertexDirItem->appendRow(v);
1104 emit patternDataChanged();
1109 QModelIndex DocumentModel::addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
1110 const QModelIndex &i_v2, const QModelIndex &i_v3 )
1111 { //CS_TODO : gestion erreur
1112 QModelIndex quadIndex;
1114 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(i_v0);
1115 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(i_v1);
1116 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(i_v2);
1117 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(i_v3);
1119 if ( hv0 && hv1 && hv2 && hv3 ){
1120 HEXA_NS::Quad* hq = _hexaDocument->addQuadVertices( hv0, hv1, hv2, hv3 );
1121 if ( BadElement(hq) ) return quadIndex;
1123 QuadItem* q = new QuadItem(hq, _entry);
1124 _quadDirItem->appendRow(q);
1125 quadIndex = q->index();
1126 emit patternDataChanged();
1132 QModelIndex DocumentModel::addQuadEdges( const QModelIndex &e0, const QModelIndex &e1,
1133 const QModelIndex &e2, const QModelIndex &e3 )
1135 QModelIndex quadIndex;
1137 HEXA_NS::Edge* he0 = getHexaPtr<HEXA_NS::Edge*>(e0);
1138 HEXA_NS::Edge* he1 = getHexaPtr<HEXA_NS::Edge*>(e1);
1139 HEXA_NS::Edge* he2 = getHexaPtr<HEXA_NS::Edge*>(e2);
1140 HEXA_NS::Edge* he3 = getHexaPtr<HEXA_NS::Edge*>(e3);
1142 if ( he0 && he1 && he2 && he3 ){
1144 HEXA_NS::Quad* hq = _hexaDocument->addQuad( he0, he1, he2, he3 );
1145 if ( BadElement(hq) ) return quadIndex;
1147 QuadItem* q = new QuadItem(hq, _entry);
1148 _quadDirItem->appendRow(q);
1149 quadIndex = q->index();
1150 emit patternDataChanged();
1156 QModelIndex DocumentModel::addHexaVertices(
1157 const QModelIndex &iv0, const QModelIndex &iv1,
1158 const QModelIndex &iv2, const QModelIndex &iv3,
1159 const QModelIndex &iv4, const QModelIndex &iv5,
1160 const QModelIndex &iv6, const QModelIndex &iv7 )
1164 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1165 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1166 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
1167 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
1168 HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
1169 HEXA_NS::Vertex* hv5 = getHexaPtr<HEXA_NS::Vertex*>(iv5);
1170 HEXA_NS::Vertex* hv6 = getHexaPtr<HEXA_NS::Vertex*>(iv6);
1171 HEXA_NS::Vertex* hv7 = getHexaPtr<HEXA_NS::Vertex*>(iv7);
1173 HEXA_NS::Hexa* hh = _hexaDocument->addHexaVertices( hv0, hv1, hv2, hv3,
1174 hv4, hv5, hv6, hv7 );
1176 if ( BadElement(hh) ) return iHexa;
1178 HexaItem* h = new HexaItem(hh, _entry);
1179 _hexaDirItem->appendRow(h);
1181 emit patternDataChanged();
1186 QModelIndex DocumentModel::addHexaQuad( const QModelIndex &i_q0, const QModelIndex &i_q1,
1187 const QModelIndex &i_q2,const QModelIndex &i_q3, const QModelIndex &i_q4, const QModelIndex &i_q5 )
1188 { //CS_TODO : gestion erreur
1189 QModelIndex hexaIndex;
1191 HEXA_NS::Quad* hq0 = getHexaPtr<HEXA_NS::Quad*>(i_q0);
1192 HEXA_NS::Quad* hq1 = getHexaPtr<HEXA_NS::Quad*>(i_q1);
1193 HEXA_NS::Quad* hq2 = getHexaPtr<HEXA_NS::Quad*>(i_q2);
1194 HEXA_NS::Quad* hq3 = getHexaPtr<HEXA_NS::Quad*>(i_q3);
1195 HEXA_NS::Quad* hq4 = getHexaPtr<HEXA_NS::Quad*>(i_q4);
1196 HEXA_NS::Quad* hq5 = getHexaPtr<HEXA_NS::Quad*>(i_q5);
1198 HEXA_NS::Hexa* hh = _hexaDocument->addHexa( hq0, hq1, hq2, hq3, hq4, hq5 );
1199 if ( BadElement(hh) ) return hexaIndex;
1201 HexaItem* h = new HexaItem(hh, _entry);
1202 _hexaDirItem->appendRow(h);
1203 hexaIndex = h->index();
1204 emit patternDataChanged();
1209 QModelIndex DocumentModel::addHexaQuads( const QModelIndexList &iquads)
1211 QModelIndex hexaIndex;
1213 HEXA_NS::Hexa* hh = NULL;
1214 HEXA_NS::Quad* hq0, *hq1, *hq2, *hq3, *hq4, *hq5 = NULL;
1216 hq0 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(0));
1217 hq1 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(1));
1218 hq2 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(2));
1219 hq3 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(3));
1220 hq4 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(4));
1221 hq5 = getHexaPtr<HEXA_NS::Quad*>(iquads.value(5));
1223 if ( hq0 && hq1 && hq2 && hq3 && hq4 && hq5 )
1224 hh = _hexaDocument->addHexa( hq0, hq1, hq2, hq3, hq4, hq5 );
1225 else if ( hq0 && hq1 && hq2 && hq3 && hq4 )
1226 hh = _hexaDocument->addHexa5Quads( hq0, hq1, hq2, hq3, hq4 );
1227 else if ( hq0 && hq1 && hq2 && hq3 )
1228 hh = _hexaDocument->addHexa4Quads( hq0, hq1, hq2, hq3 );
1229 else if ( hq0 && hq1 && hq2)
1230 hh = _hexaDocument->addHexa3Quads( hq0, hq1, hq2 );
1231 else if ( hq0 && hq1 )
1232 hh = _hexaDocument->addHexa2Quads( hq0, hq1);
1234 if ( BadElement(hh) ) return hexaIndex;
1237 unsigned int nbRows = _hexaDirItem->rowCount();
1239 hexaIndex = _hexaDirItem->child(nbRows-1)->index();
1244 QModelIndex DocumentModel::addVector( double dx, double dy, double dz )
1246 QModelIndex vectorIndex;
1248 HEXA_NS::Vector* hv = _hexaDocument->addVector(dx, dy, dz);
1249 if ( BadElement(hv) ) return vectorIndex; //Invalid index
1251 VectorItem* v = new VectorItem(hv);
1252 _vectorDirItem->appendRow(v);
1253 vectorIndex = v->index();
1258 QModelIndex DocumentModel::addVectorVertices( const QModelIndex &iv0, const QModelIndex &iv1 )
1262 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1263 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1265 HEXA_NS::Vector* hvec = _hexaDocument->addVectorVertices( hv0, hv1 );
1266 if ( BadElement(hvec) ) return iVec;
1268 VectorItem* vec = new VectorItem(hvec);
1269 _vectorDirItem->appendRow(vec);
1270 iVec = vec->index();
1276 // ************ EDIT HEXABLOCK MODEL ************
1278 bool DocumentModel::updateVertex( const QModelIndex& ivertex, double x, double y, double z )
1282 HEXA_NS::Vertex* hVertex = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1285 // hVertex->setName( name.toStdString() );
1286 hVertex->setX ( x );
1287 hVertex->setY ( y );
1288 hVertex->setZ ( z );
1289 emit patternDataChanged();
1296 bool DocumentModel::removeHexa( const QModelIndex& ihexa )
1298 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1300 int r = _hexaDocument->removeHexa( hHexa );
1309 bool DocumentModel::removeConnectedHexa( const QModelIndex& ihexa )
1311 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1313 int r = _hexaDocument->removeConnectedHexa( hHexa );
1322 bool DocumentModel::mergeVertices( const QModelIndex &iv0, const QModelIndex &iv1 ) //CS_TODO : impact sur le model?
1324 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1325 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1327 int r = _hexaDocument->mergeVertices( hv0, hv1 );
1329 updateData(); //CS_TODO more or less?
1336 bool DocumentModel::mergeEdges( const QModelIndex &ie0, const QModelIndex &ie1,
1337 const QModelIndex &iv0, const QModelIndex &iv1 )
1338 //CS_TODO : impact sur le model?
1340 HEXA_NS::Edge* he0 = getHexaPtr<HEXA_NS::Edge*>(ie0);
1341 HEXA_NS::Edge* he1 = getHexaPtr<HEXA_NS::Edge*>(ie1);
1343 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1344 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1347 int r = _hexaDocument->mergeEdges( he0, he1, hv0, hv1 );
1356 bool DocumentModel::mergeQuads( const QModelIndex& iquad0, const QModelIndex& iquad1,
1357 const QModelIndex& iv0, const QModelIndex& iv1,
1358 const QModelIndex& iv2, const QModelIndex& iv3 )
1360 HEXA_NS::Quad* hquad0 = data(iquad0, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1361 HEXA_NS::Quad* hquad1 = data(iquad1, HEXA_DATA_ROLE).value<HEXA_NS::Quad *>();
1363 HEXA_NS::Vertex* hv0 = getHexaPtr<HEXA_NS::Vertex*>(iv0);
1364 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
1365 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
1366 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
1368 int r = _hexaDocument->mergeQuads( hquad0, hquad1, hv0, hv1, hv2, hv3 );
1378 QModelIndex DocumentModel::disconnectVertex( const QModelIndex& ihexa, const QModelIndex& ivertex )
1382 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1383 HEXA_NS::Vertex* hVertex = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
1385 HEXA_NS::Elements* hElts = _hexaDocument->disconnectVertex( hHexa, hVertex );
1386 if ( BadElement(hElts) ) return iElts;
1388 updateData(); //CS_TO_CHECK
1389 ElementsItem* elts = new ElementsItem(hElts);
1390 _elementsDirItem->appendRow(elts);
1391 iElts = elts->index();
1396 QModelIndex DocumentModel::disconnectEdge( const QModelIndex& ihexa, const QModelIndex& iedge )
1400 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1401 HEXA_NS::Edge* hEdge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1403 HEXA_NS::Elements* hElts = _hexaDocument->disconnectEdge( hHexa, hEdge );
1404 if ( BadElement(hElts) ) return iElts;
1406 updateData(); //CS_TO_CHECK
1407 ElementsItem* elts = new ElementsItem(hElts);
1408 _elementsDirItem->appendRow(elts);
1409 iElts = elts->index();
1415 QModelIndex DocumentModel::disconnectEdges( const QModelIndexList& ihexas, const QModelIndexList& iedges )
1419 HEXA_NS::Hexas hHexas;
1420 HEXA_NS::Edges hEdges;
1423 HEXA_NS::Edge* hedge = NULL;
1424 foreach( const QModelIndex& iedge, iedges ){
1425 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
1426 hEdges.push_back( hedge );
1430 HEXA_NS::Hexa* hhexa = NULL;
1431 foreach( const QModelIndex& ihexa, ihexas ){
1432 hhexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1433 hHexas.push_back( hhexa );
1437 HEXA_NS::Elements* hElts = _hexaDocument->disconnectEdges( hHexas, hEdges );
1438 if ( BadElement(hElts) ) return iElts;
1440 updateData(); //CS_TO_CHECK
1441 ElementsItem* elts = new ElementsItem(hElts);
1442 _elementsDirItem->appendRow(elts);
1443 iElts = elts->index();
1449 QModelIndex DocumentModel::disconnectQuad( const QModelIndex& ihexa, const QModelIndex& iquad )
1453 HEXA_NS::Hexa* hHexa = getHexaPtr<HEXA_NS::Hexa*>(ihexa);
1454 HEXA_NS::Quad* hQuad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1456 HEXA_NS::Elements* hElts = _hexaDocument->disconnectQuad( hHexa, hQuad );
1457 if ( BadElement(hElts) ) return iElts;
1459 updateData(); //CS_TO_CHECK
1460 ElementsItem* elts = new ElementsItem(hElts);
1461 _elementsDirItem->appendRow(elts);
1462 iElts = elts->index();
1468 QModelIndex DocumentModel::makeTranslation( const QModelIndex& ielts, const QModelIndex& ivec )
1472 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1473 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1475 HEXA_NS::Elements* hNewElts = _hexaDocument->makeTranslation( hElts, hVec );
1476 if ( BadElement(hNewElts) ) return iElts;
1478 updateData(); //CS_TODO more or less?
1479 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1480 _elementsDirItem->appendRow(eltsItem);
1481 iElts = eltsItem->index();
1488 QModelIndex DocumentModel::makeScale( const QModelIndex& ielts, const QModelIndex& ivex, double k )
1492 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1493 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1495 HEXA_NS::Elements* hNewElts = _hexaDocument->makeScale( hElts, hVex, k );
1496 if ( BadElement(hNewElts) ) return iElts;
1498 updateData(); //CS_TODO more or less?
1499 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1500 _elementsDirItem->appendRow(eltsItem);
1501 iElts = eltsItem->index();
1506 QModelIndex DocumentModel::makeRotation( const QModelIndex& ielts,
1507 const QModelIndex& iv,
1508 const QModelIndex& ivec, double angle )
1512 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1513 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1514 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1516 HEXA_NS::Elements* hNewElts = _hexaDocument->makeRotation( hElts, hVex, hVec, angle );
1517 if ( BadElement(hNewElts) ) return iElts;
1519 updateData(); //CS_TODO more or less?
1520 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1521 _elementsDirItem->appendRow(eltsItem);
1522 iElts = eltsItem->index();
1528 QModelIndex DocumentModel::makeSymmetryPoint( const QModelIndex& ielts, const QModelIndex& iv )
1532 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1533 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1535 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryPoint (hElts, hVex);
1536 if ( BadElement(hNewElts) ) return iElts;
1538 updateData(); //CS_TODO more or less?
1539 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1540 _elementsDirItem->appendRow(eltsItem);
1541 iElts = eltsItem->index();
1547 QModelIndex DocumentModel::makeSymmetryLine( const QModelIndex& ielts,
1548 const QModelIndex& iv,
1549 const QModelIndex& ivec )
1553 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1554 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1555 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1558 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryLine( hElts, hVex, hVec );
1559 if ( BadElement(hNewElts) ) return iElts;
1561 updateData(); //CS_TODO more or less?
1562 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1563 _elementsDirItem->appendRow(eltsItem);
1564 iElts = eltsItem->index();
1570 QModelIndex DocumentModel::makeSymmetryPlane( const QModelIndex& ielts, const QModelIndex& iv, const QModelIndex& ivec )
1574 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1575 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(iv);
1576 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1578 HEXA_NS::Elements* hNewElts = _hexaDocument->makeSymmetryPlane( hElts, hVex, hVec );
1579 if ( BadElement(hNewElts) ) return iElts;
1581 updateData(); //CS_TODO more or less?
1582 ElementsItem* eltsItem = new ElementsItem(hNewElts);
1583 _elementsDirItem->appendRow(eltsItem);
1584 iElts = eltsItem->index();
1590 bool DocumentModel::performTranslation( const QModelIndex& ielts, const QModelIndex& ivec )
1592 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1593 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1595 int r = _hexaDocument->performTranslation (hElts, hVec);
1596 if ( r == HOK ){ //Job well done?
1606 bool DocumentModel::performScale( const QModelIndex& ielts, const QModelIndex& ivex, double k )
1608 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1609 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1611 int r = _hexaDocument->performScale (hElts, hVex, k);
1621 bool DocumentModel::performRotation( const QModelIndex& ielts, const QModelIndex& ivex, const QModelIndex& ivec, double angle )
1623 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1624 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1625 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1627 int r = _hexaDocument-> performRotation( hElts, hVex, hVec, angle );
1638 bool DocumentModel::performSymmetryPoint( const QModelIndex& ielts, const QModelIndex& ivex )
1640 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1641 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1643 int r = _hexaDocument->performSymmetryPoint( hElts, hVex );
1653 bool DocumentModel::performSymmetryLine( const QModelIndex& ielts, const QModelIndex& ivex, const QModelIndex& ivec )
1655 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1656 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1657 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1659 int r = _hexaDocument->performSymmetryLine( hElts, hVex, hVec );
1669 bool DocumentModel::performSymmetryPlane( const QModelIndex& ielts,
1670 const QModelIndex& ivex,
1671 const QModelIndex& ivec )
1673 HEXA_NS::Elements* hElts = getHexaPtr<HEXA_NS::Elements*>(ielts);
1674 HEXA_NS::Vertex* hVex = getHexaPtr<HEXA_NS::Vertex*>(ivex);
1675 HEXA_NS::Vector* hVec = getHexaPtr<HEXA_NS::Vector*>(ivec);
1677 int r = _hexaDocument->performSymmetryPlane( hElts, hVex, hVec );
1686 QModelIndex DocumentModel::replace( const QModelIndexList& iquadsPattern,
1687 const QModelIndex& ip1, const QModelIndex& ic1,
1688 const QModelIndex& ip2, const QModelIndex& ic2,
1689 const QModelIndex& ip3, const QModelIndex& ic3 )
1693 HEXA_NS::Vertex* hp1 = getHexaPtr<HEXA_NS::Vertex*>(ip1);
1694 HEXA_NS::Vertex* hc1 = getHexaPtr<HEXA_NS::Vertex*>(ic1);
1695 HEXA_NS::Vertex* hp2 = getHexaPtr<HEXA_NS::Vertex*>(ip2);
1696 HEXA_NS::Vertex* hc2 = getHexaPtr<HEXA_NS::Vertex*>(ic2);
1697 HEXA_NS::Vertex* hp3 = getHexaPtr<HEXA_NS::Vertex*>(ip3);
1698 HEXA_NS::Vertex* hc3 = getHexaPtr<HEXA_NS::Vertex*>(ic3);
1700 HEXA_NS::Quads hquads;
1701 HEXA_NS::Quad* hquad = NULL;
1702 foreach( const QModelIndex& iquad, iquadsPattern ){
1703 hquad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1704 hquads.push_back( hquad );
1707 HEXA_NS::Elements* helts = _hexaDocument->replace( hquads,
1708 hp1, hc1, hp2, hc2, hp3, hc3 );
1709 if ( BadElement(helts) ) return ielts;
1712 ElementsItem* eltsItem = new ElementsItem(helts);
1713 _elementsDirItem->appendRow(eltsItem);
1714 ielts = eltsItem->index();
1719 QModelIndex DocumentModel::replace( const QModelIndexList& iquads_source,
1720 const QModelIndexList& iquads_dest,
1721 const QModelIndex& ip1_source, const QModelIndex& ic1_dest,
1722 const QModelIndex& ip2_source, const QModelIndex& ic2_dest,
1723 const QModelIndex& ip3_source, const QModelIndex& ic3_dest)
1727 HEXA_NS::Vertex* hp1 = getHexaPtr<HEXA_NS::Vertex*>(ip1_source);
1728 HEXA_NS::Vertex* hp2 = getHexaPtr<HEXA_NS::Vertex*>(ip2_source);
1729 HEXA_NS::Vertex* hp3 = getHexaPtr<HEXA_NS::Vertex*>(ip3_source);
1730 HEXA_NS::Vertex* hc1 = getHexaPtr<HEXA_NS::Vertex*>(ic1_dest);
1731 HEXA_NS::Vertex* hc2 = getHexaPtr<HEXA_NS::Vertex*>(ic2_dest);
1732 HEXA_NS::Vertex* hc3 = getHexaPtr<HEXA_NS::Vertex*>(ic3_dest);
1734 HEXA_NS::Quads hquads_source, hquads_dest;
1735 HEXA_NS::Quad* hquad = NULL;
1736 foreach( const QModelIndex& iquad, iquads_source ){
1737 hquad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1738 hquads_source.push_back( hquad );
1741 foreach( const QModelIndex& iquad, iquads_dest) {
1742 hquad = getHexaPtr<HEXA_NS::Quad*>(iquad);
1743 hquads_dest.push_back(hquad);
1746 HEXA_NS::Elements* helts = _hexaDocument->replaceHexas( hquads_source,
1748 hp1, hc1, hp2, hc2, hp3, hc3);
1749 if ( BadElement(helts) )
1753 ElementsItem* eltsItem = new ElementsItem(helts);
1754 _elementsDirItem->appendRow(eltsItem);
1755 ielts = eltsItem->index();
1760 QModelIndex DocumentModel::getGeomModelIndex(QString& id) const
1763 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1765 // ** get the model index of the geom element having this ID
1766 HEXA_NS::SubShape* eltPtr = getGeomPtr(id);
1767 HEXA_NS::VertexShape* geomVertex = dynamic_cast<HEXA_NS::VertexShape*>(eltPtr);
1768 HEXA_NS::EdgeShape* geomEdge = dynamic_cast<HEXA_NS::EdgeShape*>(eltPtr);
1769 HEXA_NS::FaceShape* geomFace = dynamic_cast<HEXA_NS::FaceShape*>(eltPtr);
1770 if (geomVertex != NULL)
1771 result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomVertex));
1772 if (geomEdge != NULL)
1773 result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomEdge));
1774 if (geomFace != NULL)
1775 result = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomFace));
1780 QMultiMap< QString, int > DocumentModel::getAssocShapesIds(const QModelIndex& dataIndex)
1782 QMultiMap< QString, int > result;
1783 HEXA_NS::NewShape* mainShape;
1784 HEXA_NS::VertexShape* node;
1785 HEXA_NS::EdgeShape* line;
1786 HEXA_NS::FaceShape* face;
1790 PatternDataSelectionModel* pdsm = HEXABLOCKGUI::currentDocGView->getPatternDataSelectionModel();
1791 QModelIndexList assocsInd = pdsm->getGeomAssociations(dataIndex);
1792 foreach( const QModelIndex& anAssoc, assocsInd )
1794 node = getHexaPtr<HEXA_NS::VertexShape*>(anAssoc);
1795 line = getHexaPtr<HEXA_NS::EdgeShape*>(anAssoc);
1796 face = getHexaPtr<HEXA_NS::FaceShape*>(anAssoc);
1800 mainShape = node->getParentShape();
1801 if (mainShape != NULL)
1803 shapeName = mainShape->getName();
1804 subid = node->getIdent();
1807 else if (line != NULL)
1809 mainShape = line->getParentShape();
1810 if (mainShape != NULL)
1812 shapeName = mainShape->getName();
1813 subid = line->getIdent();
1816 else if (face != NULL)
1818 mainShape = face->getParentShape();
1819 if (mainShape != NULL)
1821 shapeName = mainShape->getName();
1822 subid = face->getIdent();
1826 if (!shapeName.isEmpty())
1827 result.insert( shapeName, subid );
1829 shapeName = QString();
1834 bool DocumentModel::setVertexAssociation( const QModelIndex& iVertex, double x, double y, double z)
1836 HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex *>(iVertex);
1838 if (vertex == NULL || _hexaDocument == NULL || vertex->setAssociation(x, y, z) != HOK)
1841 HEXA_NS::VertexShape* assoc = vertex->getAssociation();
1844 HEXA_NS::NewShape* mainSh = assoc->getParentShape();
1845 setData( iVertex, QVariant::fromValue(QString(mainSh->getName())+","+QString::number(assoc->getIdent())+";"), HEXA_ASSOC_ENTRY_ROLE );
1851 bool DocumentModel::setVertexAssociation( const QModelIndex& iVertex, const QModelIndex& iGeomVertex)
1853 //parameters control
1855 HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex *>(iVertex);
1856 HEXA_NS::VertexShape* geomVertex = getHexaPtr<HEXA_NS::VertexShape*>(iGeomVertex);
1857 if (_hexaDocument == NULL || vertex == NULL || geomVertex == NULL) return false;
1858 HEXA_NS::NewShape* mainShape = geomVertex->getParentShape();
1859 if (mainShape == NULL) return false;
1862 if (vertex->setAssociation(geomVertex) != HOK)
1865 //update association state in the model
1866 newAssoc = QString(mainShape->getName()) + "," + QString::number(geomVertex->getIdent()) + ";";
1867 setData( iVertex, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1872 bool DocumentModel::addEdgeAssociation( const QModelIndex& iEdge, const QModelIndex& iGeomEdge, double start, double end)
1874 //parameters control
1875 QString currentAssoc, newAssoc;
1876 HEXA_NS::Edge* edge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
1877 HEXA_NS::EdgeShape* geomEdge = getHexaPtr<HEXA_NS::EdgeShape*>(iGeomEdge);
1878 if (_hexaDocument == NULL || edge == NULL ||
1879 geomEdge == NULL || start > end) return false;
1880 HEXA_NS::NewShape* mainShape = geomEdge->getParentShape();
1881 if (mainShape == NULL) return false;
1883 //add association in the engine side
1884 if (edge->addAssociation(geomEdge, start, end) != HOK)
1887 //add/update association in the model side (UI)
1888 currentAssoc = data(iEdge, HEXA_ASSOC_ENTRY_ROLE).toString();
1889 newAssoc = QString(mainShape->getName()) + "," + QString::number(geomEdge->getIdent()) + ";";
1890 if (!currentAssoc.isEmpty()) newAssoc = currentAssoc + newAssoc;
1892 setData( iEdge, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1898 bool DocumentModel::addQuadAssociation (const QModelIndex& iQuad, const QModelIndex& iGeomFace)
1900 //parameters control
1901 QString currentAssoc, newAssoc;
1902 HEXA_NS::Quad* quad = getHexaPtr<HEXA_NS::Quad*>(iQuad);
1903 HEXA_NS::FaceShape* geomFace = getHexaPtr<HEXA_NS::FaceShape*>(iGeomFace);
1904 if (_hexaDocument == NULL || quad == NULL || geomFace == NULL)
1906 HEXA_NS::NewShape* mainShape = geomFace->getParentShape();
1907 if (mainShape == NULL) return false;
1910 if (quad->addAssociation(geomFace) != HOK)
1913 //update association
1914 currentAssoc = data( iQuad, HEXA_ASSOC_ENTRY_ROLE).toString();
1915 newAssoc = QString(mainShape->getName()) + "," + QString::number(geomFace->getIdent()) + ";";
1916 if (!currentAssoc.isEmpty()) newAssoc = currentAssoc + newAssoc;
1917 setData( iQuad, QVariant::fromValue(newAssoc), HEXA_ASSOC_ENTRY_ROLE );
1923 QModelIndex DocumentModel::getVertexAssociation(const QModelIndex& iVertex)
1925 HEXA_NS::Vertex* vertex = getHexaPtr<HEXA_NS::Vertex*>(iVertex);
1927 return QModelIndex();
1929 //get the associated geom vertex
1930 HEXA_NS::VertexShape* geomVertex = vertex->getAssociation();
1931 if (geomVertex == NULL)
1932 return QModelIndex();
1934 //convert geom vertex to qmodelindex
1935 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1937 return QModelIndex();
1939 return pgsm->indexBy(HEXA_DATA_ROLE, QVariant::fromValue(geomVertex));
1943 QModelIndexList DocumentModel::getEdgeAssociations(const QModelIndex& iEdge)
1945 QModelIndexList result;
1946 HEXA_NS::Edge* edge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
1947 if (edge == NULL) return result;
1949 HEXA_NS::EdgeShape* geomEdge;
1950 HEXA_NS::AssoEdge* anEdgeAssoc;
1952 PatternGeomSelectionModel* pGSModel = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1953 int nbAssocs = edge->countAssociation();
1954 for (int i = 0; i < nbAssocs; ++i)
1956 anEdgeAssoc = edge->getAssociation(i);
1957 if (anEdgeAssoc == NULL) continue;
1958 geomEdge = anEdgeAssoc->getEdgeShape();
1959 if (geomEdge == NULL) continue;
1960 result << pGSModel->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomEdge));
1967 QModelIndexList DocumentModel::getQuadAssociations(const QModelIndex& iQuad)
1969 QModelIndexList result;
1970 QModelIndex geomQuadIndex;
1971 HEXA_NS::Quad* quad = getHexaPtr<HEXA_NS::Quad*>(iQuad);
1972 if (quad == NULL) return result;
1974 if (HEXABLOCKGUI::currentDocGView == NULL) return result;
1975 PatternGeomSelectionModel* pgsm = HEXABLOCKGUI::currentDocGView->getPatternGeomSelectionModel();
1976 PatternGeomModel* pgm = HEXABLOCKGUI::currentDocGView->getPatternGeomModel();
1977 if (pgsm == NULL || pgm == NULL) return result;
1979 HEXA_NS::FaceShape* geomFace;
1981 int nbAssocs = quad->countAssociation();
1982 for (int i = 0; i < nbAssocs; ++i)
1984 geomFace = quad->getAssociation(i);
1985 if (geomFace == NULL) continue;
1987 geomQuadIndex = pgsm->indexBy( HEXA_DATA_ROLE, QVariant::fromValue(geomFace) );
1988 result << geomQuadIndex;
1995 bool DocumentModel::associateOpenedLine( const QModelIndexList& iedges,
1996 HEXA_NS::NewShapes shapes,
1997 HEXA_NS::IntVector subIds,
2002 HEXA_NS::Edges mline;
2004 HEXA_NS::Edge* hedge = NULL;
2005 foreach( const QModelIndex& iedge, iedges ){
2006 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
2008 mline.push_back( hedge );
2011 int err = _hexaDocument->associateOpenedLine( mline, shapes, subIds, pstart, pend );
2019 bool DocumentModel::associateClosedLine( const QModelIndex& ivertex,
2020 const QModelIndexList& iedges,
2021 HEXA_NS::NewShapes shapes,
2022 HEXA_NS::IntVector subIds,
2026 HEXA_NS::Vertex* mfirst = getHexaPtr<HEXA_NS::Vertex*>(ivertex);
2027 HEXA_NS::Edges mline;
2029 HEXA_NS::Edge* hedge = NULL;
2030 foreach( const QModelIndex& iedge, iedges ){
2031 hedge = getHexaPtr<HEXA_NS::Edge*>(iedge);
2033 mline.push_back( hedge );
2036 int err = _hexaDocument->associateClosedLine( mfirst, mline, shapes, subIds, pstart, inv);
2044 // ************ GROUPS ************
2046 QModelIndex DocumentModel::addGroup( const QString& name, Group kind )
2050 HEXA_NS::Group* hGroup = _hexaDocument->addGroup( name.toLocal8Bit().constData(), kind );
2051 if ( hGroup == NULL ) return iGroup;
2053 GroupItem* groupItem = new GroupItem(hGroup);
2054 groupItem->setData( _entry, HEXA_DOC_ENTRY_ROLE );
2055 _groupDirItem->appendRow(groupItem);
2056 iGroup = groupItem->index();
2062 bool DocumentModel::removeGroup( const QModelIndex& igrp )
2064 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2065 int r = _hexaDocument->removeGroup ( hGroup );
2068 removeRow( igrp.row(), igrp.parent());
2076 QModelIndexList DocumentModel::getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const
2078 QModelIndexList iElements;
2080 HEXA_NS::Group* g = iGroup.data(HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2081 if ( g == NULL ) return iElements;
2083 QModelIndexList iFound;
2085 HEXA_NS::EltBase* eltBase = NULL;
2086 int nbElement = g->countElement();
2087 for ( int nr = 0; nr < nbElement; ++nr ){
2088 eltBase = g->getElement( nr );
2089 kind = g->getKind();
2091 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: q = QVariant::fromValue( (HEXA_NS::Hexa *)eltBase ); break;
2092 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: q = QVariant::fromValue( (HEXA_NS::Quad *)eltBase ); break;
2093 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: q = QVariant::fromValue( (HEXA_NS::Edge *)eltBase ); break;
2094 case HEXA_NS::VertexNode: q = QVariant::fromValue( (HEXA_NS::Vertex *)eltBase ); break;
2096 iFound = match( index(0, 0),
2100 Qt::MatchRecursive );
2101 if ( !iFound.isEmpty() )
2102 iElements << iFound[0];
2107 // 7.4 Boite: éditer un groupe
2108 void DocumentModel::setGroupName( const QModelIndex& igrp, const QString& name )
2110 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2113 hGroup->setName( name.toLocal8Bit().constData() );
2114 setData(igrp, QVariant::fromValue( name ) );
2118 bool DocumentModel::addGroupElement( const QModelIndex& igrp, const QModelIndex& ielt )
2120 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2121 if (hGroup == NULL) return false;
2123 HEXA_NS::EltBase* hElt = NULL;
2124 switch ( hGroup->getKind() ){
2125 case HEXA_NS::HexaCell: case HEXA_NS::HexaNode: hElt = getHexaPtr<HEXA_NS::Hexa*>(ielt); break;
2126 case HEXA_NS::QuadCell: case HEXA_NS::QuadNode: hElt = getHexaPtr<HEXA_NS::Quad*>(ielt); break;
2127 case HEXA_NS::EdgeCell: case HEXA_NS::EdgeNode: hElt = getHexaPtr<HEXA_NS::Edge*>(ielt); break;
2128 case HEXA_NS::VertexNode: hElt = getHexaPtr<HEXA_NS::Vertex*>(ielt); break;
2133 res = hGroup->addElement( hElt );
2135 if ( res == HOK ) return true;
2140 bool DocumentModel::removeGroupElement( const QModelIndex& igrp, int nro )
2141 { //CS_TODO : remove child?
2142 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2143 if (hGroup == NULL) return false;
2145 if (hGroup->removeElement( nro ) == HOK) return true;
2150 bool DocumentModel::clearGroupElement( const QModelIndex& igrp )
2152 HEXA_NS::Group* hGroup = data(igrp, HEXA_DATA_ROLE).value<HEXA_NS::Group *>();
2154 if ( hGroup != NULL)
2156 hGroup->clearElement();
2162 // ************ LAWS ************
2165 QModelIndex DocumentModel::addLaw( const QString& name, int nbnodes )
2169 HEXA_NS::Law* hLaw = _hexaDocument->addLaw( name.toLocal8Bit().constData(), nbnodes );
2170 if ( BadElement(hLaw) ) return iLaw;
2172 LawItem* lawItem = new LawItem(hLaw);
2173 _lawDirItem->appendRow(lawItem);
2174 iLaw = lawItem->index();
2179 bool DocumentModel::setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type )
2183 HEXA_NS::Law* hLaw = data(ilaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2187 ok = hLaw->setNodes( nbnodes );
2188 ( ok == HOK) ? ret = true : ret = false;
2189 ok = hLaw->setCoefficient( coeff );
2190 hLaw->setKind(type);
2197 bool DocumentModel::removeLaw( const QModelIndex& ilaw )
2199 HEXA_NS::Law* hLaw = data(ilaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2200 int r = _hexaDocument->removeLaw( hLaw );
2203 removeRow( ilaw.row(), ilaw.parent());
2210 bool DocumentModel::setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way )
2212 HEXA_NS::Propagation* hPropagation = data(iPropagation, HEXA_DATA_ROLE).value<HEXA_NS::Propagation *>();
2213 HEXA_NS::Law* hLaw = data(iLaw, HEXA_DATA_ROLE).value<HEXA_NS::Law *>();
2215 int r = hPropagation->setLaw( hLaw );
2216 hPropagation->setWay( way );
2218 if ( r == HOK ) return true;
2224 QModelIndexList DocumentModel::getPropagation( const QModelIndex& iPropagation ) const
2226 QModelIndexList iEdges;
2228 QModelIndexList iFound;
2229 HEXA_NS::Propagation* propa = iPropagation.data(HEXA_DATA_ROLE).value<HEXA_NS::Propagation *>();
2230 if ( propa == NULL ) return iEdges;
2232 const HEXA_NS::Edges& edges = propa->getEdges();
2233 for ( HEXA_NS::Edges::const_iterator anEdge = edges.begin(), endIt = edges.end();
2236 iFound = match( index(0, 0),
2238 QVariant::fromValue( *anEdge ),
2240 Qt::MatchRecursive);
2241 if ( !iFound.isEmpty() )
2242 iEdges << iFound[0];
2248 HEXA_NS::Document* DocumentModel::documentImpl()
2250 return _hexaDocument;
2253 QString DocumentModel::documentEntry()
2258 // 8.3 Boite: éditer une loi CS_TODO
2261 /*****************************************************************
2263 *****************************************************************/
2265 PatternDataModel::PatternDataModel( QObject * parent ) :
2266 QSortFilterProxyModel( parent )
2268 QString dataRegExp = QString("(%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12)").
2269 arg(VERTEX_TREE).arg(EDGE_TREE).arg(QUAD_TREE).arg(HEXA_TREE).arg(VECTOR_TREE).arg(ELEMENTS_TREE).
2270 arg(VERTEX_DIR_TREE).arg(EDGE_DIR_TREE).arg(QUAD_DIR_TREE).arg(HEXA_DIR_TREE).arg(VECTOR_DIR_TREE).
2271 arg(ELEMENTS_DIR_TREE);
2273 setFilterRole(HEXA_TREE_ROLE);
2274 setFilterRegExp ( QRegExp(dataRegExp) );
2277 // *** Pour suppression des panneaux "Builder" et "Geometry" ****/
2279 //PatternDataModel::PatternDataModel( QObject * parent ) :
2280 // QSortFilterProxyModel( parent )
2282 // 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)").
2283 // arg(VERTEX_TREE).arg(EDGE_TREE).arg(QUAD_TREE).arg(HEXA_TREE).
2284 // arg(VERTEX_DIR_TREE).arg(EDGE_DIR_TREE).arg(QUAD_DIR_TREE).
2285 // arg(HEXA_DIR_TREE).arg(VECTOR_TREE).arg(ELEMENTS_TREE).
2286 // arg(VECTOR_DIR_TREE).arg(ELEMENTS_DIR_TREE).
2287 // arg(IMPLICIT_SHAPES_TREE).arg(EXPLICIT_SHAPES_TREE).arg(CLOUD_OF_POINTS_TREE).
2288 // arg(GEOMSHAPE_TREE).arg(GEOMPOINT_TREE).arg(GEOMEDGE_TREE).arg(GEOMFACE_TREE).
2289 // arg(IMPLICIT_SHAPES_DIR_TREE).arg(EXPLICIT_SHAPES_DIR_TREE).arg(CLOUD_OF_POINTS_DIR_TREE).
2290 // arg(GEOMSHAPE_DIR_TREE).arg(GEOMPOINT_DIR_TREE).arg(GEOMEDGE_DIR_TREE).arg(GEOMFACE_DIR_TREE);
2292 // setFilterRole(HEXA_TREE_ROLE);
2293 // setFilterRegExp ( QRegExp(dataRegExp) );
2298 PatternDataModel::~PatternDataModel()
2302 HEXA_NS::Document* PatternDataModel::documentImpl()
2304 HEXA_NS::Document* doc = NULL;
2305 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2306 if (m) doc = m->documentImpl();
2310 QString PatternDataModel::documentEntry()
2313 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2314 if (m) entry = m->documentEntry();
2318 Qt::ItemFlags PatternDataModel::flags(const QModelIndex &index) const
2320 Qt::ItemFlags flags;
2322 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2324 flags = m->flags( mapToSource(index) );
2330 QVariant PatternDataModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2332 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2333 return QVariant( "Data" );
2335 return QSortFilterProxyModel::headerData ( section, orientation, role );
2340 QStandardItem* PatternDataModel::itemFromIndex ( const QModelIndex & index ) const
2342 QStandardItem *item = NULL;
2343 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2345 item = m->itemFromIndex( mapToSource(index) );
2350 //PatternBuilderModel::PatternBuilderModel( QObject * parent ) :
2351 // QSortFilterProxyModel( parent )
2353 // QString builderRegExp =QString("(%1|%2|%3|%4|%5|%6)").
2354 // arg(VECTOR_TREE).arg(ELEMENTS_TREE).
2355 // arg(CROSSELEMENTS_TREE).arg(VECTOR_DIR_TREE).arg(ELEMENTS_DIR_TREE).arg(CROSSELEMENTS_DIR_TREE);
2357 // setFilterRole( HEXA_TREE_ROLE );
2358 // setFilterRegExp ( QRegExp( builderRegExp ) );
2361 //PatternBuilderModel::~PatternBuilderModel()
2365 //Qt::ItemFlags PatternBuilderModel::flags(const QModelIndex &index) const
2367 // Qt::ItemFlags flags;
2369 // DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2370 // if ( m != NULL ){
2371 // flags = m->flags( mapToSource(index) );
2376 //QVariant PatternBuilderModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2378 // if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2379 // return QVariant( "Builder" );
2381 // return QSortFilterProxyModel::headerData ( section, orientation, role );
2385 //QStandardItem* PatternBuilderModel::itemFromIndex ( const QModelIndex & index ) const
2387 // QStandardItem *item = NULL;
2388 // DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2389 // if ( m != NULL ){
2390 // item = m->itemFromIndex( mapToSource(index) );
2395 //====================================================================
2397 //====================================================================
2398 PatternGeomModel::PatternGeomModel( QObject * parent ) :
2399 QSortFilterProxyModel( parent )
2401 QString builderRegExp =QString("(%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12|%13|%14)").
2402 arg(EXPLICIT_SHAPES_TREE).arg(IMPLICIT_SHAPES_TREE).arg(CLOUD_OF_POINTS_TREE).
2403 arg(GEOMSHAPE_TREE).arg(GEOMPOINT_TREE).arg(GEOMEDGE_TREE).arg(GEOMFACE_TREE).
2404 arg(EXPLICIT_SHAPES_DIR_TREE).arg(IMPLICIT_SHAPES_DIR_TREE).arg(CLOUD_OF_POINTS_DIR_TREE).
2405 arg(GEOMSHAPE_DIR_TREE).arg(GEOMPOINT_DIR_TREE).arg(GEOMEDGE_DIR_TREE).arg(GEOMFACE_DIR_TREE);
2407 setFilterRole( HEXA_TREE_ROLE );
2408 setFilterRegExp ( QRegExp(builderRegExp ) );
2411 PatternGeomModel::~PatternGeomModel()
2415 Qt::ItemFlags PatternGeomModel::flags(const QModelIndex &index) const
2417 Qt::ItemFlags flags;
2419 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2421 flags = m->flags( mapToSource(index) );
2426 QVariant PatternGeomModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2428 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2429 return QVariant( "Geometry" );
2431 return QSortFilterProxyModel::headerData ( section, orientation, role );
2435 QStandardItem* PatternGeomModel::itemFromIndex ( const QModelIndex & index ) const
2437 QStandardItem *item = NULL;
2438 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2440 item = m->itemFromIndex( mapToSource(index) );
2444 //==============================================================
2447 AssociationsModel::AssociationsModel( QObject * parent ) :
2448 QSortFilterProxyModel( parent )
2450 QString assocRegExp;
2452 setFilterRole( HEXA_TREE_ROLE );
2453 setFilterRegExp ( QRegExp(assocRegExp) );
2456 AssociationsModel::~AssociationsModel()
2460 Qt::ItemFlags AssociationsModel::flags(const QModelIndex &index) const
2462 Qt::ItemFlags flags;
2464 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2466 flags = m->flags( mapToSource(index) );
2471 QVariant AssociationsModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2473 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2474 return QVariant( "Associations" );
2476 return QSortFilterProxyModel::headerData ( section, orientation, role );
2480 QStandardItem* AssociationsModel::itemFromIndex ( const QModelIndex & index ) const
2482 QStandardItem *item = NULL;
2483 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2485 item = m->itemFromIndex( mapToSource(index) );
2490 GroupsModel::GroupsModel( QObject * parent ) :
2491 QSortFilterProxyModel( parent )
2493 QString groupsRegExp =QString("(%1|%2)").arg(GROUP_TREE).arg(GROUP_DIR_TREE);
2495 setFilterRole( HEXA_TREE_ROLE );
2496 setFilterRegExp ( QRegExp(groupsRegExp ) );
2499 GroupsModel::~GroupsModel()
2503 Qt::ItemFlags GroupsModel::flags(const QModelIndex &index) const
2505 Qt::ItemFlags flags;
2507 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2509 flags = m->flags( mapToSource(index) );
2514 QVariant GroupsModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2516 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2517 return QVariant( "Groups" );
2519 return QSortFilterProxyModel::headerData ( section, orientation, role );
2523 QStandardItem* GroupsModel::itemFromIndex ( const QModelIndex & index ) const
2525 QStandardItem *item = NULL;
2526 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2528 item = m->itemFromIndex( mapToSource(index) );
2533 QModelIndexList GroupsModel::getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const
2535 QModelIndexList elements;
2536 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2538 elements = m->getGroupElements( mapToSource(iGroup), kind );
2543 MeshModel::MeshModel( QObject * parent ) :
2544 QSortFilterProxyModel( parent )
2546 QString meshRegExp =QString("(%1|%2|%3|%4)").arg(LAW_TREE).arg(LAW_DIR_TREE) .arg(PROPAGATION_TREE).arg(PROPAGATION_DIR_TREE);
2548 setFilterRole( HEXA_TREE_ROLE );
2549 setFilterRegExp ( QRegExp(meshRegExp) );
2552 MeshModel::~MeshModel()
2556 Qt::ItemFlags MeshModel::flags(const QModelIndex &index) const
2558 Qt::ItemFlags flags;
2560 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2562 flags = m->flags( mapToSource(index) );
2567 QVariant MeshModel::headerData ( int section, Qt::Orientation orientation, int role ) const
2569 if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ){
2570 return QVariant( "Mesh" );
2572 return QSortFilterProxyModel::headerData ( section, orientation, role );
2576 QStandardItem* MeshModel::itemFromIndex ( const QModelIndex & index ) const
2578 QStandardItem *item = NULL;
2579 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2581 item = m->itemFromIndex( mapToSource(index) );
2586 QModelIndexList MeshModel::getPropagation( const QModelIndex& iPropagation ) const
2588 QModelIndexList edges;
2589 DocumentModel *m = dynamic_cast<DocumentModel *>( sourceModel() );
2591 edges = m->getPropagation( mapToSource(iPropagation) );
2597 // ================================== NEW ======================================
2599 // ===== CARTESIAN GRID
2601 QModelIndex DocumentModel::makeCartesianTop(int nx, int ny, int nz)
2605 HEXA_NS::Elements* helts = _hexaDocument->makeCartesianTop( nx, ny, nz );
2606 if ( BadElement(helts) )
2609 result = addElementsToTree(helts, _elementsDirItem);
2614 QModelIndex DocumentModel::makeCartesianUni(const QModelIndex& icenter,
2615 const QModelIndex& ibase, const QModelIndex& ivec, const QModelIndex& iaxis,
2616 double lx, double ly, double lz, int nx, int ny, int nz)
2620 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2621 HEXA_NS::Vector* hbase = getHexaPtr<HEXA_NS::Vector*>(ibase);
2622 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(ivec);
2623 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2625 HEXA_NS::Elements* helts = _hexaDocument->makeCartesianUni( hcenter, hbase, hvec, haxis,
2626 lx, ly, lz, nx, ny, nz);
2627 if ( BadElement(helts) )
2630 result = addElementsToTree(helts, _elementsDirItem);
2635 QModelIndex DocumentModel::makeCartesian(const QModelIndex& icenter,
2636 const QModelIndex& ibase, const QModelIndex& ivec, const QModelIndex& iaxis,
2637 vector<double>& radius, vector<double>& angles, vector<double>& heights)
2641 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2642 HEXA_NS::Vector* hbase = getHexaPtr<HEXA_NS::Vector*>(ibase);
2643 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(ivec);
2644 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
2646 HEXA_NS::Elements* helts = _hexaDocument->makeCartesian( hcenter, hbase, hvec, haxis,
2647 radius, angles, heights);
2648 if ( BadElement(helts) )
2651 result = addElementsToTree(helts, _elementsDirItem);
2659 QModelIndex DocumentModel::makeSphereTop (int nr, int na, int nh)
2663 HEXA_NS::Elements* helts = _hexaDocument->makeSphereTop( nr, na, nh );
2664 if ( BadElement(helts) )
2667 result = addElementsToTree(helts, _elementsDirItem);
2672 QModelIndex DocumentModel::makeSphereUni (QModelIndex& icenter,
2673 QModelIndex& ivec_x, QModelIndex& ivec_z,
2674 double rtrou, double rext, double ang,
2675 QModelIndex& ivplan,
2676 int nr, int na, int nh)
2680 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2681 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2682 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2683 HEXA_NS::Vertex* hvplan = getHexaPtr<HEXA_NS::Vertex*>(ivplan);
2685 HEXA_NS::Elements* helts = _hexaDocument->makeSphereUni( hcenter, hvec_x, hvec_z,
2686 rtrou, rext, ang, hvplan,
2688 result = addElementsToTree(helts, _elementsDirItem);
2693 QModelIndex DocumentModel::makeSphere (QModelIndex& icenter,
2694 QModelIndex& ivec_x, QModelIndex& ivec_z,
2695 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2699 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2700 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2701 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2703 HEXA_NS::Elements* helts = _hexaDocument->makeSphere( hcenter, hvec_x, hvec_z,
2706 result = addElementsToTree(helts, _elementsDirItem);
2713 QModelIndex DocumentModel::makeSphericalTop (int nbre, int crit)
2717 HEXA_NS::Elements* helts = _hexaDocument->makeSphericalTop(nbre, crit);
2718 if (BadElement(helts))
2721 result = addElementsToTree(helts, _elementsDirItem);
2726 QModelIndex DocumentModel::makeSphericalUni (QModelIndex& icenter,
2727 QModelIndex& ivec_x, QModelIndex& ivec_z,
2733 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2734 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2735 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2737 HEXA_NS::Elements* helts = _hexaDocument->makeSphericalUni(hcenter, hvec_x, hvec_z, rayon, nbre, crit);
2738 if (BadElement(helts))
2741 result = addElementsToTree(helts, _elementsDirItem);
2746 QModelIndex DocumentModel::makeSpherical (QModelIndex& icenter,
2747 QModelIndex& ivec_x, QModelIndex& ivec_z,
2748 vector<double>& rayon,
2753 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2754 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2755 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2757 HEXA_NS::Elements* helts = _hexaDocument->makeSpherical(hcenter, hvec_x, hvec_z, rayon, crit);
2758 if (BadElement(helts))
2761 result = addElementsToTree(helts, _elementsDirItem);
2767 QModelIndex DocumentModel::makeRindTop (int nr, int na, int nh)
2771 HEXA_NS::Elements* helts = _hexaDocument->makeRindTop(nr, na, nh);
2772 if (BadElement(helts))
2775 result = addElementsToTree(helts, _elementsDirItem);
2780 QModelIndex DocumentModel::makeRindUni (QModelIndex& icenter,
2781 QModelIndex& ivec_x, QModelIndex& ivec_z,
2782 double raytrou, double rint, double rext, double ang,
2783 QModelIndex& ivplan,
2784 int nr, int na, int nh)
2788 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2789 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2790 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2791 HEXA_NS::Vertex* hvplan = getHexaPtr<HEXA_NS::Vertex*>(ivplan);
2793 HEXA_NS::Elements* helts = _hexaDocument->makeRindUni(hcenter, hvec_x, hvec_z, raytrou, rint, rext, ang,
2794 hvplan, nr, na, nh);
2795 if (BadElement(helts))
2798 result = addElementsToTree(helts, _elementsDirItem);
2803 QModelIndex DocumentModel::makeRind (QModelIndex& icenter,
2804 QModelIndex& ivec_x, QModelIndex& ivec_z,
2805 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2809 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
2810 HEXA_NS::Vector* hvec_x = getHexaPtr<HEXA_NS::Vector*>(ivec_x);
2811 HEXA_NS::Vector* hvec_z = getHexaPtr<HEXA_NS::Vector*>(ivec_z);
2813 HEXA_NS::Elements* helts = _hexaDocument->makeRind(hcenter, hvec_x, hvec_z, tray, tang, thaut);
2814 if (BadElement(helts))
2817 result = addElementsToTree(helts, _elementsDirItem);
2822 // ======== Cylinder
2823 QModelIndex DocumentModel::makeCylinderTop(int nr, int na, int nh)
2827 HEXA_NS::Elements* helts = _hexaDocument->makeCylinderTop(nr, na, nh);
2828 if (BadElement(helts))
2831 result = addElementsToTree(helts, _elementsDirItem);
2836 QModelIndex DocumentModel::makeCylinderUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2837 double rint, double rext, double angle, double haut,
2838 int nr, int na, int nh)
2842 HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2843 HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2844 HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2846 HEXA_NS::Elements* helts = _hexaDocument->makeCylinderUni(horig, hvecx, hvecz,
2847 rint, rext, angle, haut,
2849 if (BadElement(helts))
2852 result = addElementsToTree(helts, _elementsDirItem);
2857 QModelIndex DocumentModel::makeCylinder(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2858 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2862 HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2863 HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2864 HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2866 HEXA_NS::Elements* helts = _hexaDocument->makeCylinder(horig, hvecx, hvecz, tray, tang, thaut);
2867 if (BadElement(helts))
2870 result = addElementsToTree(helts, _elementsDirItem);
2876 // ======== Cylinders
2877 QModelIndex DocumentModel::makeCylinders(QModelIndex& iorig1, QModelIndex& ivecz1, double r1, double h1,
2878 QModelIndex& iorig2, QModelIndex& ivecz2, double r2, double h2)
2882 HEXA_NS::Vertex* horig1 = getHexaPtr<HEXA_NS::Vertex*>(iorig1);
2883 HEXA_NS::Vertex* horig2 = getHexaPtr<HEXA_NS::Vertex*>(iorig2);
2884 HEXA_NS::Vector* hvecz1 = getHexaPtr<HEXA_NS::Vector*>(ivecz1);
2885 HEXA_NS::Vector* hvecz2 = getHexaPtr<HEXA_NS::Vector*>(ivecz2);
2887 HEXA_NS::BiCylinder* helts = _hexaDocument->makeCylinders(horig1, hvecz1, r1, h1,
2888 horig2, hvecz2, r2, h2);
2889 if (BadElement(helts))
2892 result = addElementsToTree(helts, _crossElementsDirItem);
2898 QModelIndex DocumentModel::makePipeTop(int nr, int na, int nh)
2902 HEXA_NS::Elements* helts = _hexaDocument->makePipeTop(nr, na, nh);
2903 if (BadElement(helts))
2906 result = addElementsToTree(helts, _elementsDirItem);
2911 QModelIndex DocumentModel::makePipeUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2912 double rint, double rext, double angle, double haut,
2913 int nr, int na, int nh)
2917 HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2918 HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2919 HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2921 HEXA_NS::Elements* helts = _hexaDocument->makePipeUni(horig, hvecx, hvecz, rint, rext, angle,
2923 if (BadElement(helts))
2926 result = addElementsToTree(helts, _elementsDirItem);
2931 QModelIndex DocumentModel::makePipe(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
2932 vector<double>& tray, vector<double>& tang, vector<double>& thaut)
2936 HEXA_NS::Vertex* horig = getHexaPtr<HEXA_NS::Vertex*>(iorig);
2937 HEXA_NS::Vector* hvecx = getHexaPtr<HEXA_NS::Vector*>(ivecx);
2938 HEXA_NS::Vector* hvecz = getHexaPtr<HEXA_NS::Vector*>(ivecz);
2940 HEXA_NS::Elements* helts = _hexaDocument->makePipe(horig, hvecx, hvecz, tray, tang, thaut);
2941 if (BadElement(helts))
2944 result = addElementsToTree(helts, _elementsDirItem);
2950 QModelIndex DocumentModel::makePipes(QModelIndex& iorig1, QModelIndex& ivecz1, double rint1, double rex1, double h1,
2951 QModelIndex& iorig2, QModelIndex& ivecz2, double rint2, double rex2, double h2)
2955 HEXA_NS::Vertex* horig1 = getHexaPtr<HEXA_NS::Vertex*>(iorig1);
2956 HEXA_NS::Vertex* horig2 = getHexaPtr<HEXA_NS::Vertex*>(iorig2);
2957 HEXA_NS::Vector* hvecz1 = getHexaPtr<HEXA_NS::Vector*>(ivecz1);
2958 HEXA_NS::Vector* hvecz2 = getHexaPtr<HEXA_NS::Vector*>(ivecz2);
2960 HEXA_NS::BiCylinder* helts = _hexaDocument->makePipes(horig1, hvecz1, rint1, rex1, h1,
2961 horig2, hvecz2, rint2, rex2, h2);
2962 if (BadElement(helts))
2965 result = addElementsToTree(helts, _crossElementsDirItem);
2970 // ======== Join Quads
2971 QModelIndex DocumentModel::joinQuadUni(QModelIndex& istart, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
2972 QModelIndex& iv3, QModelIndex& iv4, int nb)
2976 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
2977 HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
2978 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
2979 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
2980 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
2981 HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
2983 HEXA_NS::Elements* helts = _hexaDocument->joinQuadUni(hstart, hdest, hv1, hv2, hv3, hv4, nb);
2984 if (BadElement(helts))
2987 result = addElementsToTree(helts, _elementsDirItem);
2992 QModelIndex DocumentModel::joinQuad(QModelIndex& istart, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
2993 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen)
2997 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
2998 HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
2999 HEXA_NS::Vertex* hva1 = getHexaPtr<HEXA_NS::Vertex*>(iva1);
3000 HEXA_NS::Vertex* hvb1 = getHexaPtr<HEXA_NS::Vertex*>(ivb1);
3001 HEXA_NS::Vertex* hva2 = getHexaPtr<HEXA_NS::Vertex*>(iva2);
3002 HEXA_NS::Vertex* hvb2 = getHexaPtr<HEXA_NS::Vertex*>(ivb2);
3004 HEXA_NS::Elements* helts = _hexaDocument->joinQuad(hstart, hdest, hva1, hvb1, hva2, hvb2, tlen);
3005 if (BadElement(helts))
3008 result = addElementsToTree(helts, _elementsDirItem);
3013 QModelIndex DocumentModel::joinQuadsUni(QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
3014 QModelIndex& iv3, QModelIndex& iv4, int nb)
3018 HEXA_NS::Quads hstarts;
3019 int nbQuads = istarts.size();
3020 for (int i = 0; i < nbQuads; ++i)
3021 hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3023 HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
3024 HEXA_NS::Vertex* hv1 = getHexaPtr<HEXA_NS::Vertex*>(iv1);
3025 HEXA_NS::Vertex* hv2 = getHexaPtr<HEXA_NS::Vertex*>(iv2);
3026 HEXA_NS::Vertex* hv3 = getHexaPtr<HEXA_NS::Vertex*>(iv3);
3027 HEXA_NS::Vertex* hv4 = getHexaPtr<HEXA_NS::Vertex*>(iv4);
3029 HEXA_NS::Elements* helts = _hexaDocument->joinQuadsUni(hstarts, hdest, hv1, hv2, hv3, hv4, nb);
3030 if (BadElement(helts))
3033 result = addElementsToTree(helts, _elementsDirItem);
3038 QModelIndex DocumentModel::joinQuads(QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
3039 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen)
3043 HEXA_NS::Quads hstarts;
3044 int nbQuads = istarts.size();
3045 for (int i = 0; i < nbQuads; ++i)
3046 hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3048 HEXA_NS::Quad* hdest = getHexaPtr<HEXA_NS::Quad*>(idest);
3049 HEXA_NS::Vertex* hva1 = getHexaPtr<HEXA_NS::Vertex*>(iva1);
3050 HEXA_NS::Vertex* hvb1 = getHexaPtr<HEXA_NS::Vertex*>(ivb1);
3051 HEXA_NS::Vertex* hva2 = getHexaPtr<HEXA_NS::Vertex*>(iva2);
3052 HEXA_NS::Vertex* hvb2 = getHexaPtr<HEXA_NS::Vertex*>(ivb2);
3054 HEXA_NS::Elements* helts = _hexaDocument->joinQuads(hstarts, hdest, hva1, hvb1, hva2, hvb2, tlen);
3055 if (BadElement(helts))
3058 result = addElementsToTree(helts, _elementsDirItem);
3063 // ======== Quad Revolution
3064 QModelIndex DocumentModel::revolutionQuadUni(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
3065 double angle, int nbre)
3069 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3070 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
3071 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3073 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuadUni(hstart, hcenter, haxis, angle, nbre);
3074 if (BadElement(helts))
3077 result = addElementsToTree(helts, _elementsDirItem);
3082 QModelIndex DocumentModel::revolutionQuad(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
3083 vector<double>& angles)
3087 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3088 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
3089 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3091 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuad(hstart, hcenter, haxis, angles);
3092 if (BadElement(helts))
3095 result = addElementsToTree(helts, _elementsDirItem);
3100 QModelIndex DocumentModel::revolutionQuadsUni(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
3101 double angle, int nbre)
3105 HEXA_NS::Quads hstarts;
3106 int nbQuads = istarts.count();
3107 for (int i = 0; i < nbQuads; ++i)
3108 hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3110 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
3111 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3113 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuadsUni(hstarts, hcenter, haxis, angle, nbre);
3114 if (BadElement(helts))
3117 result = addElementsToTree(helts, _elementsDirItem);
3122 QModelIndex DocumentModel::revolutionQuads(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
3123 vector<double>& angles)
3127 HEXA_NS::Quads hstarts;
3128 int nbQuads = istarts.count();
3129 for (int i = 0; i < nbQuads; ++i)
3130 hstarts.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3132 HEXA_NS::Vertex* hcenter = getHexaPtr<HEXA_NS::Vertex*>(icenter);
3133 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3135 HEXA_NS::Elements* helts = _hexaDocument->revolutionQuads(hstarts, hcenter, haxis, angles);
3136 if (BadElement(helts))
3139 result = addElementsToTree(helts, _elementsDirItem);
3145 // ==== PrismQuad or ExtrudeQuad
3146 QModelIndex DocumentModel::extrudeQuadTop(QModelIndex& istart, int nbre)
3150 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3151 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadTop(hstart, nbre);
3152 if (BadElement(helts))
3155 result = addElementsToTree(helts, _elementsDirItem);
3160 QModelIndex DocumentModel::extrudeQuadUni(QModelIndex& istart, QModelIndex& dv, double len, int nbre)
3164 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3165 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(dv);
3167 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadUni(hstart, hvec, len, nbre);
3168 if (BadElement(helts))
3171 result = addElementsToTree(helts, _elementsDirItem);
3176 QModelIndex DocumentModel::extrudeQuad(QModelIndex& istart, QModelIndex& dv, vector<double>& tlen)
3180 HEXA_NS::Quad* hstart = getHexaPtr<HEXA_NS::Quad*>(istart);
3181 HEXA_NS::Vector* hvec = getHexaPtr<HEXA_NS::Vector*>(dv);
3183 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuad(hstart, hvec, tlen);
3184 if (BadElement(helts))
3186 result = addElementsToTree(helts, _elementsDirItem);
3191 QModelIndex DocumentModel::extrudeQuadsTop (QModelIndexList& istarts, int nbre)
3195 HEXA_NS::Quads hquads;
3196 int nbQuads = istarts.count();
3197 for (int i = 0; i < nbQuads; ++i)
3198 hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3200 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadsTop(hquads, nbre);
3201 if (BadElement(helts))
3203 result = addElementsToTree(helts, _elementsDirItem);
3208 QModelIndex DocumentModel::extrudeQuadsUni (QModelIndexList& istarts, QModelIndex& axis, double len, int nbre)
3212 HEXA_NS::Quads hquads;
3213 int nbQuads = istarts.count();
3214 for (int i = 0; i < nbQuads; ++i)
3215 hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3217 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(axis);
3219 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuadsUni(hquads, haxis, len, nbre);
3220 if (BadElement(helts))
3222 result = addElementsToTree(helts, _elementsDirItem);
3227 QModelIndex DocumentModel::extrudeQuads(QModelIndexList& istarts, QModelIndex& iaxis, vector<double>& tlen)
3231 HEXA_NS::Quads hquads;
3232 int nbQuads = istarts.count();
3233 for (int i=0; i < nbQuads; ++i)
3234 hquads.push_back(getHexaPtr<HEXA_NS::Quad*>(istarts[i]));
3236 HEXA_NS::Vector* haxis = getHexaPtr<HEXA_NS::Vector*>(iaxis);
3238 HEXA_NS::Elements* helts = _hexaDocument->extrudeQuads(hquads, haxis, tlen);
3239 if (BadElement(helts))
3241 result = addElementsToTree(helts, _elementsDirItem);
3247 QModelIndex DocumentModel::cutUni(QModelIndex& iEdge, int nbre)
3251 HEXA_NS::Edge* hedge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
3253 HEXA_NS::Elements* helts = _hexaDocument->cutUni(hedge, nbre);
3254 if (BadElement(helts))
3256 result = addElementsToTree(helts, _elementsDirItem);
3261 QModelIndex DocumentModel::cut(QModelIndex& iEdge, vector<double>& tlen)
3265 HEXA_NS::Edge* hedge = getHexaPtr<HEXA_NS::Edge*>(iEdge);
3267 HEXA_NS::Elements* helts = _hexaDocument->cut(hedge, tlen);
3268 if (BadElement(helts))
3270 result = addElementsToTree(helts, _elementsDirItem);
3275 // ================================== END NEW ==================================