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
76 double getLength(const QModelIndex& iEdge);
77 double getRadius(const QModelIndex& iEdge);
78 double getAngle(const QModelIndex& iEdge);
82 // void clearBuilder();
84 void clearAssociation();
89 // void fillBuilder();
91 void fillAssociation();
95 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
99 void disallowEdition();
101 void allowDataSelectionOnly();
102 void allowVertexSelectionOnly();
103 void allowEdgeSelectionOnly();
104 void allowQuadSelectionOnly();
105 void allowHexaSelectionOnly();
107 void allowVectorSelectionOnly();
108 void allowCylinderSelectionOnly();
109 void allowPipeSelectionOnly();
110 void allowElementsSelectionOnly();
111 void allowCrossElementsSelectionOnly();
113 void allowLawSelectionOnly();
115 Hex::Hex* getHexaRoot() { return Hex::Hex::getInstance(); }
117 HEXA_NS::EltBase* getHexaPtr(const QModelIndex& iElt);
119 T getHexaPtr(QModelIndex iElt)
122 return iElt.data( HEXA_DATA_ROLE ).value< T >();
127 int getNbrElt(HEXA_NS::EnumElt eltType);
128 int getNbrUsedElt(HEXA_NS::EnumElt eltType);
129 int getNbrUnusedElt(HEXA_NS::EnumElt eltType);
131 QModelIndex addElementsToTree(HEXA_NS::Elements* helts, QStandardItem* tree);
133 //associate a shape to the current document
134 bool addShape(TopoDS_Shape& forme, QString& shapeName, bool publish=true);
136 //returns the geom obj id in the document using its entry
137 QString getGeomObjName(QString& studyEntry) const {
138 return docShapesName.contains(studyEntry) ? docShapesName[studyEntry] : QString();
141 //returns the geom obj entry in the document using its id
142 QString getGeomObjEntry(QString& shapeName) const {
143 return docShapesEntry.contains(shapeName) ? docShapesEntry[shapeName] : QString();
146 //returns the document's shapes entries
147 QList<QString> getShapesEntries() const { return docShapesName.uniqueKeys(); }
149 //returns the associated geom object to the data index
150 HEXA_NS::SubShape* getGeomPtr(QString& id) const
152 if (!shapeById.contains(id))
154 return shapeById[id];
157 QModelIndex getGeomModelIndex(QString& id) const;
159 void setGeomObjName(QString& studyEntry, QString& shapeName) {docShapesName[studyEntry] = shapeName;}
160 void setGeomObjEntry(QString& shapeName, QString& studyEntry) {docShapesEntry[shapeName] = studyEntry;}
162 void setName( const QModelIndex& iElt, const QString& name );
163 bool clearEltAssociations( const QModelIndex& iElt );
164 HEXA_NS::Hexa* getQuadHexa(HEXA_NS::Quad* quad);
166 // ************ BUILD HEXABLOCK MODEL (OBSOLETE)************
167 QModelIndex addVertex( double x, double y, double z );
170 QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
171 QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
174 QModelIndex addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
175 const QModelIndex &i_v2, const QModelIndex &i_v3 );
176 QModelIndex addQuadEdges( const QModelIndex &i_e0, const QModelIndex &i_e1,
177 const QModelIndex &i_e2, const QModelIndex &i_e3 );
180 QModelIndex addHexaVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
181 const QModelIndex &i_v2, const QModelIndex &i_v3,
182 const QModelIndex &i_v4, const QModelIndex &i_v5,
183 const QModelIndex &i_v6, const QModelIndex &i_v7 );
184 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 );
186 QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
190 QModelIndex addVector( double dx, double dy, double dz );
191 QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
194 // QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r, double h );
197 // QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
201 // ===================== NEW =================================
203 // ===== CARTESIAN GRID
205 QModelIndex makeCartesianTop(int nx, int ny, int nz);
206 QModelIndex makeCartesianUni(const QModelIndex& icenter, const QModelIndex& ibase, const QModelIndex& ivec,
207 const QModelIndex& iaxis, double lx, double ly, double lz, int nx, int ny, int nz);
208 QModelIndex makeCartesian(const QModelIndex& icenter, const QModelIndex& ibase, const QModelIndex& ivec,
209 const QModelIndex& iaxis, vector<double>& radius, vector<double>& angles, vector<double>& heights);
213 QModelIndex makeSphereTop (int nr, int na, int nh);
215 QModelIndex makeSphereUni (QModelIndex& icenter,
216 QModelIndex& ivec_x, QModelIndex& ivec_z,
217 double rtrou, double rext, double ang,
219 int nr, int na, int nh);
221 QModelIndex makeSphere (QModelIndex& icenter,
222 QModelIndex& ivec_x, QModelIndex& ivec_z,
223 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
227 QModelIndex makeSphericalTop (int nbre, int crit);
229 QModelIndex makeSphericalUni (QModelIndex& icenter,
230 QModelIndex& ivec_x, QModelIndex& ivec_z,
234 QModelIndex makeSpherical (QModelIndex& icenter,
235 QModelIndex& ivec_x, QModelIndex& ivec_z,
236 vector<double>& rayon,
240 QModelIndex makeRindTop (int nr, int na, int nh);
242 QModelIndex makeRindUni (QModelIndex& icenter,
243 QModelIndex& ivec_x, QModelIndex& ivec_z,
244 double raytrou, double rint, double rext, double ang,
246 int nr, int na, int nh);
248 QModelIndex makeRind (QModelIndex& icenter,
249 QModelIndex& ivec_x, QModelIndex& ivec_z,
250 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
253 QModelIndex makeCylinderTop(int nr, int na, int nh);
255 QModelIndex makeCylinderUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
256 double rint, double rext, double angle, double haut,
257 int nr, int na, int nh);
259 QModelIndex makeCylinder (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
260 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
262 // ======== Cylinders
263 QModelIndex makeCylinders (QModelIndex& iorig1, QModelIndex& ivecz1, double r1, double h1,
264 QModelIndex& iorig2, QModelIndex& ivecz2, double r2, double h2);
267 QModelIndex makePipeTop (int nr, int na, int nh);
269 QModelIndex makePipeUni (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
270 double rint, double rext, double angle, double haut,
271 int nr, int na, int nh);
273 QModelIndex makePipe (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
274 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
277 QModelIndex makePipes (QModelIndex& iorig1, QModelIndex& ivecz1, double rint1, double rex1, double h1,
278 QModelIndex& iorig2, QModelIndex& ivecz2, double rint2, double rex2, double h2);
280 // ======== Join Quads
281 QModelIndex joinQuadUni(QModelIndex& istart, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
282 QModelIndex& iv3, QModelIndex& iv4, int nb);
284 QModelIndex joinQuad (QModelIndex& istart, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
285 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen);
287 QModelIndex joinQuadsUni (QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
288 QModelIndex& iv3, QModelIndex& iv4, int nb);
290 QModelIndex joinQuads (QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
291 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen);
293 // ======== Quad Revolution
294 QModelIndex revolutionQuadUni(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
295 double angle, int nbre);
297 QModelIndex revolutionQuad(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
298 vector<double>& angles);
300 QModelIndex revolutionQuadsUni(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
301 double angle, int nbre);
303 QModelIndex revolutionQuads(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
304 vector<double>& angles);
306 // ==== PrismQuad or ExtrudeQuad
307 QModelIndex extrudeQuadTop (QModelIndex& istart, int nbre);
308 QModelIndex extrudeQuadUni (QModelIndex& istart, QModelIndex& dv, double len, int nbre);
309 QModelIndex extrudeQuad (QModelIndex& istart, QModelIndex& dv, vector<double>& tlen);
311 QModelIndex extrudeQuadsTop (QModelIndexList& istarts, int nbre);
312 QModelIndex extrudeQuadsUni (QModelIndexList& istarts, QModelIndex& axis, double len, int nbre);
313 QModelIndex extrudeQuads (QModelIndexList& istarts, QModelIndex& iaxis, vector<double>& tlen);
316 QModelIndex cutUni (QModelIndex& iEdge, int nbre);
317 QModelIndex cut (QModelIndex& iEdge, vector<double>& tlen);
319 // ============================== END NEW ================================
321 // ************ EDIT HEXABLOCK MODEL ************
323 bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
326 bool removeHexa( const QModelIndex& hexa );
327 bool removeConnectedHexa( const QModelIndex& hexa );
329 bool mergeVertices( const QModelIndex& va, const QModelIndex& vb );
330 bool mergeEdges( const QModelIndex& ea, const QModelIndex& eb,
331 const QModelIndex& v0, const QModelIndex& v1 );
332 bool mergeQuads( const QModelIndex& qa, const QModelIndex& qb,
333 const QModelIndex& v0, const QModelIndex& v1,
334 const QModelIndex& v2, const QModelIndex& v3 );
337 QModelIndex disconnectVertex( const QModelIndex& h, const QModelIndex& v );
338 QModelIndex disconnectEdge( const QModelIndex& h, const QModelIndex& e );
339 QModelIndex disconnectQuad( const QModelIndex& h, const QModelIndex& q );
340 QModelIndex disconnectEdges( const QModelIndexList& h, const QModelIndexList& e );
343 QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
344 QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
347 QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
350 QModelIndex makeSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
351 QModelIndex makeSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
352 QModelIndex makeSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
355 bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
358 bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
361 bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
364 bool performSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
365 bool performSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
366 bool performSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
368 QModelIndex replace( const QModelIndexList& quadsPattern,
369 const QModelIndex& ip1, const QModelIndex& ic1,
370 const QModelIndex& ip2, const QModelIndex& ic2,
371 const QModelIndex& ip3, const QModelIndex& ic3 ); //NEW HEXA3
373 QModelIndex replace( const QModelIndexList& iquads_source, const QModelIndexList& iquads_dest,
374 const QModelIndex& ip1_source, const QModelIndex& ic1_dest,
375 const QModelIndex& ip2_source, const QModelIndex& ic2_dest,
376 const QModelIndex& ip3_source, const QModelIndex& ic3_dest );
379 // ************ ASSOCIATION ************
380 bool setVertexAssociation( const QModelIndex& iVertex, double x, double y, double z);
381 bool setVertexAssociation(const QModelIndex& iVertex, const QModelIndex& iGeomVertex);
382 bool addEdgeAssociation(const QModelIndex& iEdge, const QModelIndex& iGeomEdge, double start, double end);
383 bool addQuadAssociation (const QModelIndex& iQuad, const QModelIndex& iGeomFace);
385 QMultiMap< QString, int > getAssocShapesIds(const QModelIndex& dataIndex);
386 QModelIndex getVertexAssociation(const QModelIndex& iVertex);
387 QModelIndexList getEdgeAssociations(const QModelIndex& iEdge);
388 QModelIndexList getQuadAssociations(const QModelIndex& iQuad);
390 //---------- perimees -------------
391 bool associateOpenedLine( const QModelIndexList& edges,
392 const GeomObjList& assocs,
396 bool associateClosedLine( const QModelIndex& vertex,
397 const QModelIndexList& edges,
398 const GeomObjList& assocs,
403 bool associateOpenedLine( const QModelIndexList& edges,
404 HEXA_NS::NewShapes shapes,
405 HEXA_NS::IntVector subIds,
409 bool associateClosedLine( const QModelIndex& vertex,
410 const QModelIndexList& edges,
411 HEXA_NS::NewShapes shapes,
412 HEXA_NS::IntVector subIds,
416 void clearAssociation(HEXA_NS::EnumElt& eltType);
419 // ************ GROUPS ************
421 QModelIndex addGroup( const QString& name, Group kind );
424 bool removeGroup( const QModelIndex& grp );
427 QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
429 // 7.4 Boite: éditer un groupe
430 void setGroupName( const QModelIndex& grp, const QString& name );
431 bool addGroupElement( const QModelIndex& grp, const QModelIndex& elt );
432 bool removeGroupElement( const QModelIndex& grp, int nro ); //CS_TODO
433 bool clearGroupElement( const QModelIndex& grp );
436 // ************ LAWS ************
438 QModelIndex addLaw( const QString& name, int nbnodes );
439 bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
440 bool removeLaw( const QModelIndex& law );
441 bool setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way );
442 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
445 HEXA_NS::Document* documentImpl();
446 QString documentEntry();
449 void patternDataChanged();
450 void nameChanged(const QString& name);
453 QTemporaryFile *_hexaFile;
454 HEXA_NS::Document *_hexaDocument;
458 QMap<QString, QString> docShapesEntry;
459 QMap<QString, QString> docShapesName;
460 QMap<QString, HEXA_NS::SubShape*> shapeById;
462 QMap<QString, QString> _assocName; // clé: id; valeur: nom
463 bool _disallowEdition;
466 QStandardItem *_vertexDirItem;
467 QStandardItem *_edgeDirItem;
468 QStandardItem *_quadDirItem;
469 QStandardItem *_hexaDirItem;
472 QStandardItem *_vectorDirItem;
473 QStandardItem *_elementsDirItem;
474 QStandardItem *_crossElementsDirItem;
477 QStandardItem *_explicitShapesDirItem;
478 QStandardItem *_implicitShapesDirItem;
479 QStandardItem *_cloudOfPointsDirItem;
485 QStandardItem *_groupDirItem;
488 QStandardItem *_lawDirItem;
489 QStandardItem *_propagationDirItem;
491 Qt::ItemFlags _vertexItemFlags;
492 Qt::ItemFlags _edgeItemFlags;
493 Qt::ItemFlags _quadItemFlags;
494 Qt::ItemFlags _hexaItemFlags;
496 Qt::ItemFlags _vectorItemFlags;
497 Qt::ItemFlags _elementsItemFlags;
498 Qt::ItemFlags _crossElementsItemFlags;
500 Qt::ItemFlags _groupItemFlags;
501 Qt::ItemFlags _lawItemFlags;
502 Qt::ItemFlags _propagationItemFlags;
506 class PatternDataModel : public QSortFilterProxyModel
509 PatternDataModel( QObject * parent = 0 );
510 virtual ~PatternDataModel();
512 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
513 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
515 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
517 HEXA_NS::Document* documentImpl();
518 QString documentEntry();
522 // class PatternBuilderModel : public QSortFilterProxyModel
525 // PatternBuilderModel( QObject * parent = 0 );
526 // virtual ~PatternBuilderModel();
528 // virtual Qt::ItemFlags flags(const QModelIndex &index) const;
529 // virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
530 // QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
533 class PatternGeomModel : public QSortFilterProxyModel
536 PatternGeomModel( QObject* parent = 0);
537 virtual ~PatternGeomModel();
539 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
540 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
542 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
546 class AssociationsModel : public QSortFilterProxyModel
549 AssociationsModel( QObject * parent = 0 );
550 virtual ~AssociationsModel();
552 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
553 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
554 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
558 class GroupsModel : public QSortFilterProxyModel
561 GroupsModel( QObject * parent = 0 );
562 virtual ~GroupsModel();
564 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
565 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
566 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
568 QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
572 class MeshModel : public QSortFilterProxyModel
575 MeshModel( QObject * parent = 0 );
576 virtual ~MeshModel();
578 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
579 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
580 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
583 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;