1 // Copyright (C) 2009-2014 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, or (at your option) any later version.
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_
23 #include "HEXABLOCKGUI_Export.hxx"
25 #include <QTemporaryFile>
26 #include <QStandardItemModel>
27 #include <QSortFilterProxyModel>
29 #include "HEXABLOCKGUI_DocumentItem.hxx"
30 #include "HexDocument.hxx"
31 #include "HexNewShape.hxx"
39 class HEXABLOCK_EXPORT DocumentModel : public QStandardItemModel
46 QString shapeName; //main shape name
47 QString shapeEntry; //main shape entry
49 QString subId; // sub-shape id (if it's a sub shape)
55 typedef HEXA_NS::EnumGroup Group;
56 typedef HEXA_NS::KindLaw KindLaw;
58 typedef QList<GeomObj> GeomObjList;
60 DocumentModel( HEXA_NS::Document* doc, const QString& entry, QObject * parent = 0 );
61 DocumentModel( int rows, int columns, QObject * parent = 0 );
63 virtual ~DocumentModel();
66 void setName(const QString& name);
68 HEXA_NS::Document* getHexaDocument() const { return _hexaDocument; }
69 void load( const QString& xmlFileName );
70 void load(); //Loads the current document
71 void save( const QString& xmlFileName );
73 void updateGeomTree();
74 void refresh(); //refresh data
77 double getLength(const QModelIndex& iEdge);
78 double getRadius(const QModelIndex& iEdge);
79 double getAngle(const QModelIndex& iEdge);
83 // void clearBuilder();
85 void clearAssociation();
90 // void fillBuilder();
92 void fillAssociation();
96 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
100 void disallowEdition();
102 void allowDataSelectionOnly();
103 void allowVertexSelectionOnly();
104 void allowEdgeSelectionOnly();
105 void allowQuadSelectionOnly();
106 void allowHexaSelectionOnly();
108 void allowVectorSelectionOnly();
109 void allowCylinderSelectionOnly();
110 void allowPipeSelectionOnly();
111 void allowElementsSelectionOnly();
112 void allowCrossElementsSelectionOnly();
114 void allowLawSelectionOnly();
116 Hex::Hex* getHexaRoot() { return Hex::Hex::getInstance(); }
118 HEXA_NS::EltBase* getHexaPtr(const QModelIndex& iElt);
120 T getHexaPtr(QModelIndex iElt)
123 return iElt.data( HEXA_DATA_ROLE ).value< T >();
128 int getNbrElt(HEXA_NS::EnumElt eltType);
129 int getNbrUsedElt(HEXA_NS::EnumElt eltType);
130 int getNbrUnusedElt(HEXA_NS::EnumElt eltType);
132 QModelIndex addElementsToTree(HEXA_NS::Elements* helts, QStandardItem* tree);
134 //associate a shape to the current document
135 bool addShape(TopoDS_Shape& forme, QString& shapeName, bool publish=true);
137 //returns the geom obj id in the document using its entry
138 QString getGeomObjName(QString& studyEntry) const {
139 return docShapesName.contains(studyEntry) ? docShapesName[studyEntry] : QString();
142 //returns the geom obj entry in the document using its id
143 QString getGeomObjEntry(QString& shapeName) const {
144 return docShapesEntry.contains(shapeName) ? docShapesEntry[shapeName] : QString();
147 //returns the document's shapes entries
148 QList<QString> getShapesEntries() const { return docShapesName.uniqueKeys(); }
150 //returns the associated geom object to the data index
151 HEXA_NS::SubShape* getGeomPtr(QString& id) const
153 if (!shapeById.contains(id))
155 return shapeById[id];
158 QModelIndex getGeomModelIndex(QString& id) const;
160 void setGeomObjName(QString& studyEntry, QString& shapeName) {docShapesName[studyEntry] = shapeName;}
161 void setGeomObjEntry(QString& shapeName, QString& studyEntry) {docShapesEntry[shapeName] = studyEntry;}
163 void setName( const QModelIndex& iElt, const QString& name );
164 bool clearEltAssociations( const QModelIndex& iElt );
165 HEXA_NS::Hexa* getQuadHexa(HEXA_NS::Quad* quad);
167 // ************ BUILD HEXABLOCK MODEL (OBSOLETE)************
168 QModelIndex addVertex( double x, double y, double z );
171 QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
172 QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
175 QModelIndex addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
176 const QModelIndex &i_v2, const QModelIndex &i_v3 );
177 QModelIndex addQuadEdges( const QModelIndex &i_e0, const QModelIndex &i_e1,
178 const QModelIndex &i_e2, const QModelIndex &i_e3 );
181 QModelIndex addHexaVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
182 const QModelIndex &i_v2, const QModelIndex &i_v3,
183 const QModelIndex &i_v4, const QModelIndex &i_v5,
184 const QModelIndex &i_v6, const QModelIndex &i_v7 );
185 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 );
187 QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
191 QModelIndex addVector( double dx, double dy, double dz );
192 QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
195 // QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r, double h );
198 // QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
202 // ===================== NEW =================================
204 // ===== CARTESIAN GRID
206 QModelIndex makeCartesianTop(int nx, int ny, int nz);
207 QModelIndex makeCartesianUni(const QModelIndex& icenter, const QModelIndex& ibase, const QModelIndex& ivec,
208 const QModelIndex& iaxis, double lx, double ly, double lz, int nx, int ny, int nz);
209 QModelIndex makeCartesian(const QModelIndex& icenter, const QModelIndex& ibase, const QModelIndex& ivec,
210 const QModelIndex& iaxis, vector<double>& radius, vector<double>& angles, vector<double>& heights);
214 QModelIndex makeSphereTop (int nr, int na, int nh);
216 QModelIndex makeSphereUni (QModelIndex& icenter,
217 QModelIndex& ivec_x, QModelIndex& ivec_z,
218 double rtrou, double rext, double ang,
220 int nr, int na, int nh);
222 QModelIndex makeSphere (QModelIndex& icenter,
223 QModelIndex& ivec_x, QModelIndex& ivec_z,
224 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
228 QModelIndex makeSphericalTop (int nbre, int crit);
230 QModelIndex makeSphericalUni (QModelIndex& icenter,
231 QModelIndex& ivec_x, QModelIndex& ivec_z,
235 QModelIndex makeSpherical (QModelIndex& icenter,
236 QModelIndex& ivec_x, QModelIndex& ivec_z,
237 vector<double>& rayon,
241 QModelIndex makeRindTop (int nr, int na, int nh);
243 QModelIndex makeRindUni (QModelIndex& icenter,
244 QModelIndex& ivec_x, QModelIndex& ivec_z,
245 double raytrou, double rint, double rext, double ang,
247 int nr, int na, int nh);
249 QModelIndex makeRind (QModelIndex& icenter,
250 QModelIndex& ivec_x, QModelIndex& ivec_z,
251 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
254 QModelIndex makeCylinderTop(int nr, int na, int nh);
256 QModelIndex makeCylinderUni(QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
257 double rint, double rext, double angle, double haut,
258 int nr, int na, int nh);
260 QModelIndex makeCylinder (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
261 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
263 // ======== Cylinders
264 QModelIndex makeCylinders (QModelIndex& iorig1, QModelIndex& ivecz1, double r1, double h1,
265 QModelIndex& iorig2, QModelIndex& ivecz2, double r2, double h2);
268 QModelIndex makePipeTop (int nr, int na, int nh);
270 QModelIndex makePipeUni (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
271 double rint, double rext, double angle, double haut,
272 int nr, int na, int nh);
274 QModelIndex makePipe (QModelIndex& iorig, QModelIndex& ivecx, QModelIndex& ivecz,
275 vector<double>& tray, vector<double>& tang, vector<double>& thaut);
278 QModelIndex makePipes (QModelIndex& iorig1, QModelIndex& ivecz1, double rint1, double rex1, double h1,
279 QModelIndex& iorig2, QModelIndex& ivecz2, double rint2, double rex2, double h2);
281 // ======== Join Quads
282 QModelIndex joinQuadUni(QModelIndex& istart, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
283 QModelIndex& iv3, QModelIndex& iv4, int nb);
285 QModelIndex joinQuad (QModelIndex& istart, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
286 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen);
288 QModelIndex joinQuadsUni (QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iv1, QModelIndex& iv2,
289 QModelIndex& iv3, QModelIndex& iv4, int nb);
291 QModelIndex joinQuads (QModelIndexList& istarts, QModelIndex& idest, QModelIndex& iva1, QModelIndex& ivb1,
292 QModelIndex& iva2, QModelIndex& ivb2, vector<double>& tlen);
294 // ======== Quad Revolution
295 QModelIndex revolutionQuadUni(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
296 double angle, int nbre);
298 QModelIndex revolutionQuad(QModelIndex& istart, QModelIndex& icenter, QModelIndex& iaxis,
299 vector<double>& angles);
301 QModelIndex revolutionQuadsUni(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
302 double angle, int nbre);
304 QModelIndex revolutionQuads(QModelIndexList& istarts, QModelIndex& icenter, QModelIndex& iaxis,
305 vector<double>& angles);
307 // ==== PrismQuad or ExtrudeQuad
308 QModelIndex extrudeQuadTop (QModelIndex& istart, int nbre);
309 QModelIndex extrudeQuadUni (QModelIndex& istart, QModelIndex& dv, double len, int nbre);
310 QModelIndex extrudeQuad (QModelIndex& istart, QModelIndex& dv, vector<double>& tlen);
312 QModelIndex extrudeQuadsTop (QModelIndexList& istarts, int nbre);
313 QModelIndex extrudeQuadsUni (QModelIndexList& istarts, QModelIndex& axis, double len, int nbre);
314 QModelIndex extrudeQuads (QModelIndexList& istarts, QModelIndex& iaxis, vector<double>& tlen);
317 QModelIndex cutUni (QModelIndex& iEdge, int nbre);
318 QModelIndex cut (QModelIndex& iEdge, vector<double>& tlen);
320 // ============================== END NEW ================================
322 // ************ EDIT HEXABLOCK MODEL ************
324 bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
327 bool removeHexa( const QModelIndex& hexa );
328 bool removeConnectedHexa( const QModelIndex& hexa );
330 bool mergeVertices( const QModelIndex& va, const QModelIndex& vb );
331 bool mergeEdges( const QModelIndex& ea, const QModelIndex& eb,
332 const QModelIndex& v0, const QModelIndex& v1 );
333 bool mergeQuads( const QModelIndex& qa, const QModelIndex& qb,
334 const QModelIndex& v0, const QModelIndex& v1,
335 const QModelIndex& v2, const QModelIndex& v3 );
338 QModelIndex disconnectVertex( const QModelIndex& h, const QModelIndex& v );
339 QModelIndex disconnectEdge( const QModelIndex& h, const QModelIndex& e );
340 QModelIndex disconnectQuad( const QModelIndex& h, const QModelIndex& q );
341 QModelIndex disconnectEdges( const QModelIndexList& h, const QModelIndexList& e );
344 QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
345 QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
348 QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
351 QModelIndex makeSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
352 QModelIndex makeSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
353 QModelIndex makeSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
356 bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
359 bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
362 bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
365 bool performSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
366 bool performSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
367 bool performSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
369 QModelIndex replace( const QModelIndexList& iquads_source, const QModelIndexList& iquads_dest,
370 const QModelIndex& ip1_source, const QModelIndex& ic1_dest,
371 const QModelIndex& ip2_source, const QModelIndex& ic2_dest);
374 // ************ ASSOCIATION ************
375 bool setVertexAssociation( const QModelIndex& iVertex, double x, double y, double z);
376 bool setVertexAssociation(const QModelIndex& iVertex, const QModelIndex& iGeomVertex);
377 bool addEdgeAssociation(const QModelIndex& iEdge, const QModelIndex& iGeomEdge, double start, double end);
378 bool addQuadAssociation (const QModelIndex& iQuad, const QModelIndex& iGeomFace);
380 QMultiMap< QString, int > getAssocShapesIds(const QModelIndex& dataIndex);
381 QModelIndex getVertexAssociation(const QModelIndex& iVertex);
382 QModelIndexList getEdgeAssociations(const QModelIndex& iEdge);
383 QModelIndexList getQuadAssociations(const QModelIndex& iQuad);
385 //---------- perimees -------------
386 bool associateOpenedLine( const QModelIndexList& edges,
387 const GeomObjList& assocs,
391 bool associateClosedLine( const QModelIndex& vertex,
392 const QModelIndexList& edges,
393 const GeomObjList& assocs,
398 bool associateOpenedLine( const QModelIndexList& edges,
399 HEXA_NS::NewShapes shapes,
400 HEXA_NS::IntVector subIds,
404 bool associateClosedLine( const QModelIndex& vertex,
405 const QModelIndexList& edges,
406 HEXA_NS::NewShapes shapes,
407 HEXA_NS::IntVector subIds,
411 void clearAssociation(HEXA_NS::EnumElt& eltType);
414 // ************ GROUPS ************
416 QModelIndex addGroup( const QString& name, Group kind );
419 bool removeGroup( const QModelIndex& grp );
422 QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
424 // 7.4 Boite: éditer un groupe
425 void setGroupName( const QModelIndex& grp, const QString& name );
426 bool addGroupElement( const QModelIndex& grp, const QModelIndex& elt );
427 bool removeGroupElement( const QModelIndex& grp, int nro ); //CS_TODO
428 bool clearGroupElement( const QModelIndex& grp );
431 // ************ LAWS ************
433 QModelIndex addLaw( const QString& name, int nbnodes );
434 bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
435 bool removeLaw( const QModelIndex& law );
436 bool setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way );
437 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
440 HEXA_NS::Document* documentImpl();
441 QString documentEntry();
444 void patternDataChanged();
445 void nameChanged(const QString& name);
448 QTemporaryFile *_hexaFile;
449 HEXA_NS::Document *_hexaDocument;
453 QMap<QString, QString> docShapesEntry;
454 QMap<QString, QString> docShapesName;
455 QMap<QString, HEXA_NS::SubShape*> shapeById;
457 QMap<QString, QString> _assocName; // clé: id; valeur: nom
458 bool _disallowEdition;
461 QStandardItem *_vertexDirItem;
462 QStandardItem *_edgeDirItem;
463 QStandardItem *_quadDirItem;
464 QStandardItem *_hexaDirItem;
467 QStandardItem *_vectorDirItem;
468 QStandardItem *_elementsDirItem;
469 QStandardItem *_crossElementsDirItem;
472 QStandardItem *_explicitShapesDirItem;
473 QStandardItem *_implicitShapesDirItem;
474 QStandardItem *_cloudOfPointsDirItem;
480 QStandardItem *_groupDirItem;
483 QStandardItem *_lawDirItem;
484 QStandardItem *_propagationDirItem;
486 Qt::ItemFlags _vertexItemFlags;
487 Qt::ItemFlags _edgeItemFlags;
488 Qt::ItemFlags _quadItemFlags;
489 Qt::ItemFlags _hexaItemFlags;
491 Qt::ItemFlags _vectorItemFlags;
492 Qt::ItemFlags _elementsItemFlags;
493 Qt::ItemFlags _crossElementsItemFlags;
495 Qt::ItemFlags _groupItemFlags;
496 Qt::ItemFlags _lawItemFlags;
497 Qt::ItemFlags _propagationItemFlags;
501 class PatternDataModel : public QSortFilterProxyModel
504 PatternDataModel( QObject * parent = 0 );
505 virtual ~PatternDataModel();
507 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
508 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
510 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
512 HEXA_NS::Document* documentImpl();
513 QString documentEntry();
517 // class PatternBuilderModel : public QSortFilterProxyModel
520 // PatternBuilderModel( QObject * parent = 0 );
521 // virtual ~PatternBuilderModel();
523 // virtual Qt::ItemFlags flags(const QModelIndex &index) const;
524 // virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
525 // QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
528 class PatternGeomModel : public QSortFilterProxyModel
531 PatternGeomModel( QObject* parent = 0);
532 virtual ~PatternGeomModel();
534 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
535 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
537 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
541 class AssociationsModel : public QSortFilterProxyModel
544 AssociationsModel( QObject * parent = 0 );
545 virtual ~AssociationsModel();
547 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
548 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
549 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
553 class GroupsModel : public QSortFilterProxyModel
556 GroupsModel( QObject * parent = 0 );
557 virtual ~GroupsModel();
559 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
560 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
561 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
563 QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
567 class MeshModel : public QSortFilterProxyModel
570 MeshModel( QObject * parent = 0 );
571 virtual ~MeshModel();
573 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
574 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
575 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
578 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;