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 #ifndef _HEXABLOCKGUI_DOCUMENTMODEL_HXX_
21 #define _HEXABLOCKGUI_DOCUMENTMODEL_HXX_
24 #include <QTemporaryFile>
25 #include <QStandardItemModel>
26 #include <QSortFilterProxyModel>
28 #include "HEXABLOCKGUI_DocumentItem.hxx"
29 #include "HexDocument.hxx"
30 #include "HexNewShape.hxx"
38 class HexaExport DocumentModel : public QStandardItemModel
45 QString shapeName; //main shape name
46 QString shapeEntry; //main shape entry
48 QString subId; // sub-shape id (if it's a sub shape)
54 typedef HEXA_NS::EnumGroup Group;
55 typedef HEXA_NS::KindLaw KindLaw;
57 typedef QList<GeomObj> GeomObjList;
59 DocumentModel( HEXA_NS::Document* doc, const QString& entry, QObject * parent = 0 );
60 DocumentModel( int rows, int columns, QObject * parent = 0 );
62 virtual ~DocumentModel();
65 void setName(const QString& name);
67 HEXA_NS::Document* getHexaDocument() const { return _hexaDocument; }
68 void load( const QString& xmlFileName );
69 void load(); //Loads the current document
70 void save( const QString& xmlFileName );
72 void updateGeomTree();
73 void refresh(); //refresh data
78 // void clearBuilder();
80 void clearAssociation();
85 // void fillBuilder();
87 void fillAssociation();
91 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
95 void disallowEdition();
97 void allowDataSelectionOnly();
98 void allowVertexSelectionOnly();
99 void allowEdgeSelectionOnly();
100 void allowQuadSelectionOnly();
101 void allowHexaSelectionOnly();
103 void allowVectorSelectionOnly();
104 void allowCylinderSelectionOnly();
105 void allowPipeSelectionOnly();
106 void allowElementsSelectionOnly();
107 void allowCrossElementsSelectionOnly();
109 void allowLawSelectionOnly();
111 Hex::Hex* getHexaRoot() { return Hex::Hex::getInstance(); }
113 HEXA_NS::EltBase* getHexaPtr(const QModelIndex& iElt);
115 T getHexaPtr(QModelIndex iElt)
118 return iElt.data( HEXA_DATA_ROLE ).value< T >();
123 int getNbrElt(HEXA_NS::EnumElt eltType);
124 int getNbrUsedElt(HEXA_NS::EnumElt eltType);
125 int getNbrUnusedElt(HEXA_NS::EnumElt eltType);
127 QModelIndex addElementsToTree(HEXA_NS::Elements* helts, QStandardItem* tree);
129 //associate a shape to the current document
130 bool addShape(TopoDS_Shape& forme, QString& shapeName, bool publish=true);
132 //returns the geom obj id in the document using its entry
133 QString getGeomObjName(QString& studyEntry) const {
134 return docShapesName.contains(studyEntry) ? docShapesName[studyEntry] : QString();
137 //returns the geom obj entry in the document using its id
138 QString getGeomObjEntry(QString& shapeName) const {
139 return docShapesEntry.contains(shapeName) ? docShapesEntry[shapeName] : QString();
142 //returns the document's shapes entries
143 QList<QString> getShapesEntries() const { return docShapesName.uniqueKeys(); }
145 //returns the associated geom object to the data index
146 HEXA_NS::SubShape* getGeomPtr(QString& id) const
148 if (!shapeById.contains(id))
150 return shapeById[id];
153 QModelIndex getGeomModelIndex(QString& id) const;
155 void setGeomObjName(QString& studyEntry, QString& shapeName) {docShapesName[studyEntry] = shapeName;}
156 void setGeomObjEntry(QString& shapeName, QString& studyEntry) {docShapesEntry[shapeName] = studyEntry;}
158 void setName( const QModelIndex& iElt, const QString& name );
159 bool clearEltAssociations( const QModelIndex& iElt );
160 HEXA_NS::Hexa* getQuadHexa(HEXA_NS::Quad* quad);
162 // ************ BUILD HEXABLOCK MODEL (OBSOLETE)************
163 QModelIndex addVertex( double x, double y, double z );
166 QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
167 QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
170 QModelIndex addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
171 const QModelIndex &i_v2, const QModelIndex &i_v3 );
172 QModelIndex addQuadEdges( const QModelIndex &i_e0, const QModelIndex &i_e1,
173 const QModelIndex &i_e2, const QModelIndex &i_e3 );
176 QModelIndex addHexaVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
177 const QModelIndex &i_v2, const QModelIndex &i_v3,
178 const QModelIndex &i_v4, const QModelIndex &i_v5,
179 const QModelIndex &i_v6, const QModelIndex &i_v7 );
180 QModelIndex addHexaQuad( const QModelIndex &i_q0, const QModelIndex &i_q1, const QModelIndex &i_q2, const QModelIndex &i_q3, const QModelIndex &i_q4, const QModelIndex &i_q5 );
182 QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
186 QModelIndex addVector( double dx, double dy, double dz );
187 QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
190 // QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r, double h );
193 // QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
197 // ===================== NEW =================================
199 // ===== CARTESIAN GRID
201 QModelIndex makeCartesianTop(int nx, int ny, int nz);
202 QModelIndex makeCartesianUni(const QModelIndex& icenter, const QModelIndex& ibase, const QModelIndex& ivec,
203 const QModelIndex& iaxis, double lx, double ly, double lz, int nx, int ny, int nz);
204 QModelIndex makeCartesian(const QModelIndex& icenter, const QModelIndex& ibase, const QModelIndex& ivec,
205 const QModelIndex& iaxis, vector<double>& radius, vector<double>& angles, vector<double>& heights);
209 QModelIndex makeSphereTop (int nr, int na, int nh);
211 QModelIndex makeSphereUni (QModelIndex& icenter,
212 QModelIndex& ivec_x, QModelIndex& ivec_z,
213 double rtrou, double rext, double ang,
215 int nr, int na, int nh);
217 QModelIndex makeSphere (QModelIndex& icenter,
218 QModelIndex& ivec_x, QModelIndex& ivec_z,
219 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
223 QModelIndex makeSphericalTop (int nbre, int crit);
225 QModelIndex makeSphericalUni (QModelIndex& icenter,
226 QModelIndex& ivec_x, QModelIndex& ivec_z,
230 QModelIndex makeSpherical (QModelIndex& icenter,
231 QModelIndex& ivec_x, QModelIndex& ivec_z,
232 vector<double>& rayon,
236 QModelIndex makeRindTop (int nr, int na, int nh);
238 QModelIndex makeRindUni (QModelIndex& icenter,
239 QModelIndex& ivec_x, QModelIndex& ivec_z,
240 double raytrou, double rint, double rext, double ang,
242 int nr, int na, int nh);
244 QModelIndex makeRind (QModelIndex& icenter,
245 QModelIndex& ivec_x, QModelIndex& ivec_z,
246 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
249 QModelIndex makeCylinderTop(int nr, int na, int nh);
251 QModelIndex makeCylinderUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
252 double rint, double rext, double angle, double haut,
253 int nr, int na, int nh);
255 QModelIndex makeCylinder (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
256 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
258 // ======== Cylinders
259 QModelIndex makeCylinders (QModelIndex& iorig1, QModelIndex& ivecz1, double r1, double h1,
260 QModelIndex& iorig2, QModelIndex& ivecz2, double r2, double h2);
263 QModelIndex makePipeTop (int nr, int na, int nh);
265 QModelIndex makePipeUni (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
266 double rint, double rext, double angle, double haut,
267 int nr, int na, int nh);
269 QModelIndex makePipe (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
270 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
273 QModelIndex makePipes (QModelIndex& iorig1, QModelIndex& ivecz1, double rint1, double rex1, double h1,
274 QModelIndex& iorig2, QModelIndex& ivecz2, double rint2, double rex2, double h2);
276 // ======== Join Quads
277 QModelIndex joinQuadUni(QModelIndex& istart, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
278 QModelIndex& iv3, QModelIndex& iv4, int nb);
280 QModelIndex joinQuad (QModelIndex& istart, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
281 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen);
283 QModelIndex joinQuadsUni (QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
284 QModelIndex& iv3, QModelIndex& iv4, int nb);
286 QModelIndex joinQuads (QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
287 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen);
289 // ======== Quad Revolution
290 QModelIndex revolutionQuadUni(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
291 double angle, int nbre);
293 QModelIndex revolutionQuad(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
294 vector<double>& angles);
296 QModelIndex revolutionQuadsUni(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
297 double angle, int nbre);
299 QModelIndex revolutionQuads(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
300 vector<double>& angles);
302 // ==== PrismQuad or ExtrudeQuad
303 QModelIndex extrudeQuadTop (QModelIndex& istart, int nbre);
304 QModelIndex extrudeQuadUni (QModelIndex& istart, QModelIndex& dv, double len, int nbre);
305 QModelIndex extrudeQuad (QModelIndex& istart, QModelIndex& dv, vector<double>& tlen);
307 QModelIndex extrudeQuadsTop (QModelIndexList& istarts, int nbre);
308 QModelIndex extrudeQuadsUni (QModelIndexList& istarts, QModelIndex& axis, double len, int nbre);
309 QModelIndex extrudeQuads (QModelIndexList& istarts, QModelIndex& iaxis, vector<double>& tlen);
312 QModelIndex cutUni (QModelIndex& iEdge, int nbre);
313 QModelIndex cut (QModelIndex& iEdge, vector<double>& tlen);
315 // ============================== END NEW ================================
317 // ************ EDIT HEXABLOCK MODEL ************
319 bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
322 bool removeHexa( const QModelIndex& hexa );
323 bool removeConnectedHexa( const QModelIndex& hexa );
325 bool mergeVertices( const QModelIndex& va, const QModelIndex& vb );
326 bool mergeEdges( const QModelIndex& ea, const QModelIndex& eb,
327 const QModelIndex& v0, const QModelIndex& v1 );
328 bool mergeQuads( const QModelIndex& qa, const QModelIndex& qb,
329 const QModelIndex& v0, const QModelIndex& v1,
330 const QModelIndex& v2, const QModelIndex& v3 );
333 QModelIndex disconnectVertex( const QModelIndex& h, const QModelIndex& v );
334 QModelIndex disconnectEdge( const QModelIndex& h, const QModelIndex& e );
335 QModelIndex disconnectQuad( const QModelIndex& h, const QModelIndex& q );
336 QModelIndex disconnectEdges( const QModelIndexList& h, const QModelIndexList& e );
339 QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
340 QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
343 QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
346 QModelIndex makeSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
347 QModelIndex makeSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
348 QModelIndex makeSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
351 bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
354 bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
357 bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
360 bool performSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
361 bool performSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
362 bool performSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
364 QModelIndex replace( const QModelIndexList& quadsPattern,
365 const QModelIndex& p1, const QModelIndex& c1,
366 const QModelIndex& p2, const QModelIndex& c2,
367 const QModelIndex& p3, const QModelIndex& c3 ); //NEW HEXA3
370 // ************ ASSOCIATION ************
371 bool setVertexAssociation( const QModelIndex& iVertex, double x, double y, double z);
372 bool setVertexAssociation(const QModelIndex& iVertex, const QModelIndex& iGeomVertex);
373 bool addEdgeAssociation(const QModelIndex& iEdge, const QModelIndex& iGeomEdge, double start, double end);
374 bool addQuadAssociation (const QModelIndex& iQuad, const QModelIndex& iGeomFace);
376 QMultiMap< QString, int > getAssocShapesIds(const QModelIndex& dataIndex);
377 QModelIndex getVertexAssociation(const QModelIndex& iVertex);
378 QModelIndexList getEdgeAssociations(const QModelIndex& iEdge);
379 QModelIndexList getQuadAssociations(const QModelIndex& iQuad);
381 //---------- perimees -------------
382 bool associateOpenedLine( const QModelIndexList& edges,
383 const GeomObjList& assocs,
387 bool associateClosedLine( const QModelIndex& vertex,
388 const QModelIndexList& edges,
389 const GeomObjList& assocs,
394 bool associateOpenedLine( const QModelIndexList& edges,
395 HEXA_NS::NewShapes shapes,
396 HEXA_NS::IntVector subIds,
400 bool associateClosedLine( const QModelIndex& vertex,
401 const QModelIndexList& edges,
402 HEXA_NS::NewShapes shapes,
403 HEXA_NS::IntVector subIds,
407 void clearAssociation(HEXA_NS::EnumElt& eltType);
410 // ************ GROUPS ************
412 QModelIndex addGroup( const QString& name, Group kind );
415 bool removeGroup( const QModelIndex& grp );
418 QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
420 // 7.4 Boite: éditer un groupe
421 void setGroupName( const QModelIndex& grp, const QString& name );
422 bool addGroupElement( const QModelIndex& grp, const QModelIndex& elt );
423 bool removeGroupElement( const QModelIndex& grp, int nro ); //CS_TODO
424 bool clearGroupElement( const QModelIndex& grp );
427 // ************ LAWS ************
429 QModelIndex addLaw( const QString& name, int nbnodes );
430 bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
431 bool removeLaw( const QModelIndex& law );
432 bool setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way );
433 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
436 HEXA_NS::Document* documentImpl();
437 QString documentEntry();
440 void patternDataChanged();
441 void nameChanged(const QString& name);
444 QTemporaryFile *_hexaFile;
445 HEXA_NS::Document *_hexaDocument;
449 QMap<QString, QString> docShapesEntry;
450 QMap<QString, QString> docShapesName;
451 QMap<QString, HEXA_NS::SubShape*> shapeById;
453 QMap<QString, QString> _assocName; // clé: id; valeur: nom
454 bool _disallowEdition;
457 QStandardItem *_vertexDirItem;
458 QStandardItem *_edgeDirItem;
459 QStandardItem *_quadDirItem;
460 QStandardItem *_hexaDirItem;
463 QStandardItem *_vectorDirItem;
464 QStandardItem *_elementsDirItem;
465 QStandardItem *_crossElementsDirItem;
468 QStandardItem *_explicitShapesDirItem;
469 QStandardItem *_implicitShapesDirItem;
470 QStandardItem *_cloudOfPointsDirItem;
476 QStandardItem *_groupDirItem;
479 QStandardItem *_lawDirItem;
480 QStandardItem *_propagationDirItem;
483 Qt::ItemFlags _vertexItemFlags;
484 Qt::ItemFlags _edgeItemFlags;
485 Qt::ItemFlags _quadItemFlags;
486 Qt::ItemFlags _hexaItemFlags;
488 Qt::ItemFlags _vectorItemFlags;
489 Qt::ItemFlags _elementsItemFlags;
490 Qt::ItemFlags _crossElementsItemFlags;
492 Qt::ItemFlags _groupItemFlags;
493 Qt::ItemFlags _lawItemFlags;
494 Qt::ItemFlags _propagationItemFlags;
499 class PatternDataModel : public QSortFilterProxyModel
502 PatternDataModel( QObject * parent = 0 );
503 virtual ~PatternDataModel();
505 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
506 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
508 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
510 HEXA_NS::Document* documentImpl();
511 QString documentEntry();
515 // class PatternBuilderModel : public QSortFilterProxyModel
518 // PatternBuilderModel( QObject * parent = 0 );
519 // virtual ~PatternBuilderModel();
521 // virtual Qt::ItemFlags flags(const QModelIndex &index) const;
522 // virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
523 // QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
526 class PatternGeomModel : public QSortFilterProxyModel
529 PatternGeomModel( QObject* parent = 0);
530 virtual ~PatternGeomModel();
532 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
533 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
535 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
539 class AssociationsModel : public QSortFilterProxyModel
542 AssociationsModel( QObject * parent = 0 );
543 virtual ~AssociationsModel();
545 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
546 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
547 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
551 class GroupsModel : public QSortFilterProxyModel
554 GroupsModel( QObject * parent = 0 );
555 virtual ~GroupsModel();
557 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
558 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
559 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
561 QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
565 class MeshModel : public QSortFilterProxyModel
568 MeshModel( QObject * parent = 0 );
569 virtual ~MeshModel();
571 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
572 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
573 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
576 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;