1 // Copyright (C) 2009-2012 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 "GEOM_GenericObjPtr.h"
30 #include "HEXABLOCKGUI_DocumentItem.hxx"
31 #include "HexDocument.hxx"
32 #include "HexNewShape.hxx"
39 class DocumentModel : public QStandardItemModel
44 // enum EnumGroup { HexaCell, QuadCell, EdgeCell,
45 // HexaNode, QuadNode, EdgeNode, Vertex_Node};
46 typedef HEXA_NS::EnumGroup Group;
47 typedef HEXA_NS::KindLaw KindLaw;
53 QString subid; // sub-shape id
59 typedef QList<GeomObj> GeomObjList;
61 DocumentModel( HEXA_NS::Document* doc, const QString& entry, QObject * parent = 0 );
62 DocumentModel( int rows, int columns, QObject * parent = 0 );
64 virtual ~DocumentModel();
67 void setName(const QString& name);
69 HEXA_NS::Document* getHexaDocument() const { return _hexaDocument; }
70 void load( const QString& xmlFileName );
71 void load(); //Loads the current document
72 void save( const QString& xmlFileName );
73 struct GeomObj* convertToGeomObj(GEOM::GeomObjPtr geomObjPtr);
75 void refresh(); //refresh data
82 void clearAssociation();
89 void fillAssociation();
93 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
97 void disallowEdition();
99 // void setDefaultSelection();
100 // void allowSelection();
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();
116 HEXA_NS::EltBase* getHexaPtr(const QModelIndex& iElt);
118 T getHexaPtr(QModelIndex iElt)
121 return iElt.data( HEXA_DATA_ROLE ).value< T >();
126 int getNbrElt(HEXA_NS::EnumElt eltType);
127 int getNbrUsedElt(HEXA_NS::EnumElt eltType);
128 int getNbrUnusedElt(HEXA_NS::EnumElt eltType);
130 //associate a shape to the current document
131 bool addShape(TopoDS_Shape& forme, QString& shapeName);
133 //returns the geom obj id in the document using its entry
134 QString getGeomObjName(QString& studyEntry) {
135 return docShapesName.contains(studyEntry) ? docShapesName[studyEntry] : QString();
138 //returns the geom obj entry in the document using its id
139 QString getGeomObjEntry(QString& shapeName) {
140 return docShapesEntry.contains(shapeName) ? docShapesEntry[shapeName] : QString();
143 //returns the document's shapes entries
144 QList<QString> getShapesEntries() const { return docShapesName.uniqueKeys(); }
146 //returns the associated geom index to the data index
147 HEXA_NS::SubShape* getGeomPtr(QString& id)
149 if (!shapeById.contains(id)) return NULL;
150 return shapeById[id];
153 void setGeomObjName(QString& studyEntry, QString& shapeName) {docShapesName[studyEntry] = shapeName;}
154 void setGeomObjEntry(QString& shapeName, QString& studyEntry) {docShapesEntry[shapeName] = studyEntry;}
156 void setName( const QModelIndex& iElt, const QString& name );
157 bool clearEltAssociations( const QModelIndex& iElt );
158 HEXA_NS::Hexa* getQuadHexa(HEXA_NS::Quad* quad);
160 // ************ BUILD HEXABLOCK MODEL ************
161 QModelIndex addVertex( double x, double y, double z );
164 QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
165 QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
168 QModelIndex addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
169 const QModelIndex &i_v2, const QModelIndex &i_v3 );
170 QModelIndex addQuadEdges( const QModelIndex &i_e0, const QModelIndex &i_e1,
171 const QModelIndex &i_e2, const QModelIndex &i_e3 );
174 QModelIndex addHexaVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
175 const QModelIndex &i_v2, const QModelIndex &i_v3,
176 const QModelIndex &i_v4, const QModelIndex &i_v5,
177 const QModelIndex &i_v6, const QModelIndex &i_v7 );
178 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 );
180 QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
184 QModelIndex addVector( double dx, double dy, double dz );
185 QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
188 QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r, double h );
191 QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
195 QModelIndex makeCartesian( const QModelIndex& ivex,
196 const QModelIndex& ivecx, const QModelIndex& ivecy, const QModelIndex& ivecz,
197 long nx, long ny, long nz);
199 QModelIndex makeCartesian( const QModelIndex& ivex,
200 const QModelIndex& ivec,
201 int nx, int ny, int nz );
203 QModelIndex makeCylindrical( const QModelIndex& i_pt,
204 const QModelIndex& i_vx, const QModelIndex& i_vz,
205 double dr, double da, double dl,
206 long nr, long na, long nl,
209 QModelIndex makeCylindricals(
210 const QModelIndex& i_center, const QModelIndex& i_base, const QModelIndex& i_height,
211 QList< double> i_radius, QList<double> i_angles, QList<double> i_heights,
212 bool fill = false ); //NEW HEXA3
214 QModelIndex makeSpherical( const QModelIndex& i_v, const QModelIndex& i_vec, int nb, double k = 1 ); //CS_TO_DEL
216 QModelIndex makeSpherical( const QModelIndex& i_center, double rayon, int nb, double k = 1 );
219 QModelIndex makeCylinder( const QModelIndex& cyl, const QModelIndex& vec,
220 int nr, int na, int nl );
223 QModelIndex makePipe( const QModelIndex& pipe, const QModelIndex& vecx,
224 int nr, int na, int nl );
227 QModelIndex makeCylinders(const QModelIndex& cyl1, const QModelIndex& cyl2);
230 QModelIndex makePipes( const QModelIndex& pipe1, const QModelIndex& pipe2 );
234 QModelIndex makeRind( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
235 double radext, double radint, double radhole,
236 const QModelIndex& plorig,
237 int nrad, int nang, int nhaut ); //NEW HEXA3
239 QModelIndex makePartRind( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
240 double radext, double radint, double radhole,
241 const QModelIndex& plorig, double angle,
242 int nrad, int nang, int nhaut ); //NEW HEXA3
244 QModelIndex makeSphere( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
245 double radius, double radhole,
246 const QModelIndex& plorig,
247 int nrad, int nang, int nhaut ); //NEW HEXA3
249 QModelIndex makePartSphere( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
250 double radius, double radhole,
251 const QModelIndex& plorig, double angle,
252 int nrad, int nang, int nhaut ); //NEW HEXA3
254 // ************ EDIT HEXABLOCK MODEL ************
256 bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
259 bool removeHexa( const QModelIndex& hexa );
260 bool removeConnectedHexa( const QModelIndex& hexa );
264 QModelIndex prismQuad( const QModelIndex& quad, const QModelIndex& dv, int nb);
265 QModelIndex prismQuads( const QModelIndexList& quads, const QModelIndex& dv, int nb);
266 QModelIndex prismQuads( const QModelIndexList& quads, const QModelIndex& dv, std::vector<double>, int nb=0);
269 QModelIndex joinQuad( const QModelIndex& start_q, const QModelIndex& dest_q,
270 const QModelIndex& v0, const QModelIndex& v1,
271 const QModelIndex& v2, const QModelIndex& v3,
275 QModelIndex joinQuads( const QModelIndexList& start_q, const QModelIndex& dest_q,
276 const QModelIndex& v0, const QModelIndex& v1,
277 const QModelIndex& v2, const QModelIndex& v3,
282 bool mergeVertices( const QModelIndex& va, const QModelIndex& vb );
283 bool mergeEdges( const QModelIndex& ea, const QModelIndex& eb,
284 const QModelIndex& v0, const QModelIndex& v1 );
285 bool mergeQuads( const QModelIndex& qa, const QModelIndex& qb,
286 const QModelIndex& v0, const QModelIndex& v1,
287 const QModelIndex& v2, const QModelIndex& v3 );
290 QModelIndex disconnectVertex( const QModelIndex& h, const QModelIndex& v );
291 QModelIndex disconnectEdge( const QModelIndex& h, const QModelIndex& e );
292 QModelIndex disconnectQuad( const QModelIndex& h, const QModelIndex& q );
293 QModelIndex disconnectEdges( const QModelIndexList& h, const QModelIndexList& e );
296 QModelIndex cutEdge( const QModelIndex &e, int nbcuts );
299 QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
300 QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
303 QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
306 QModelIndex makeSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
307 QModelIndex makeSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
308 QModelIndex makeSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
311 bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
314 bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
317 bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
320 bool performSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
321 bool performSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
322 bool performSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
325 QModelIndex revolutionQuads( const QModelIndexList& startQuads, const QModelIndex& center,
326 const QModelIndex& vec_axis, const QList<double>& angles); //NEW HEXA3
328 QModelIndex replace( const QModelIndexList& quadsPattern,
329 const QModelIndex& p1, const QModelIndex& c1,
330 const QModelIndex& p2, const QModelIndex& c2,
331 const QModelIndex& p3, const QModelIndex& c3 ); //NEW HEXA3
337 // ************ ASSOCIATION ************
338 // elt is Vertex, Edge, Quad
339 // void addAssociation( const QModelIndex& elt, const GeomObj& assoc ); //perime
340 // QList<GeomObj> getAssociations( const QModelIndex& elt ); //perime
342 bool setVertexAssociation( const QModelIndex& iVertex, double x, double y, double z);
343 bool setVertexAssociation(const QModelIndex& iVertex, const QModelIndex& iGeomVertex);
344 bool addEdgeAssociation(const QModelIndex& iEdge, const QModelIndex& iGeomEdge, double start, double end);
345 bool addQuadAssociation (const QModelIndex& iQuad, const QModelIndex& iGeomFace);
347 QMultiMap< QString, int > getAssocShapesIds(const QModelIndex& dataIndex);
348 QModelIndex getVertexAssociation(const QModelIndex& iVertex);
349 QList<GeomObj> getEdgeAssociations(const QModelIndex& iEdge);
350 QModelIndexList getQuadAssociations(const QModelIndex& iQuad);
352 //---------- perimees -------------
353 bool associateOpenedLine( const QModelIndexList& edges,
354 const GeomObjList& assocs,
358 bool associateClosedLine( const QModelIndex& vertex,
359 const QModelIndexList& edges,
360 const GeomObjList& assocs,
365 bool associateOpenedLine( const QModelIndexList& edges,
366 HEXA_NS::NewShapes shapes,
367 HEXA_NS::IntVector subIds,
371 bool associateClosedLine( const QModelIndex& vertex,
372 const QModelIndexList& edges,
373 HEXA_NS::NewShapes shapes,
374 HEXA_NS::IntVector subIds,
378 void clearAssociation(HEXA_NS::EnumElt& eltType);
381 // ************ GROUPS ************
384 QModelIndex addGroup( const QString& name, Group kind );
387 bool removeGroup( const QModelIndex& grp );
390 QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
392 // 7.4 Boite: éditer un groupe
393 void setGroupName( const QModelIndex& grp, const QString& name );
394 bool addGroupElement( const QModelIndex& grp, const QModelIndex& elt );
395 bool removeGroupElement( const QModelIndex& grp, int nro ); //CS_TODO
396 bool clearGroupElement( const QModelIndex& grp );
399 // ************ LAWS ************
402 QModelIndex addLaw( const QString& name, int nbnodes );
404 // 8.2 Boite: créer une loi
408 // int setNodes (int nbre);
409 // int setCoefficient (double coeff);
410 // void setKind (KindLaw type);
413 bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
416 bool removeLaw( const QModelIndex& law );
418 // 8.3 Boite: éditer une loi
422 // 9.1 Boite: poser une loi de discrétisation sur une propagation
423 // int setLaw (Law* loi);
424 // void setWay (bool sens);
425 bool setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way );
426 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
434 HEXA_NS::Document* documentImpl();
435 QString documentEntry();
436 // QModelIndex indexBy( int role, const QString& value );
439 void patternDataChanged();
440 void nameChanged(const QString& name);
443 QTemporaryFile *_hexaFile;
444 HEXA_NS::Document *_hexaDocument;
448 QMap<QString, QString> docShapesEntry;
449 QMap<QString, QString> docShapesName;
450 QMap<QString, HEXA_NS::SubShape*> shapeById;
452 QMap<QString, QString> _assocName; // clé: id; valeur: nom
453 bool _disallowEdition;
456 QStandardItem *_vertexDirItem;
457 QStandardItem *_edgeDirItem;
458 QStandardItem *_quadDirItem;
459 QStandardItem *_hexaDirItem;
462 QStandardItem *_vectorDirItem;
463 QStandardItem *_cylinderDirItem;
464 QStandardItem *_pipeDirItem;
465 QStandardItem *_elementsDirItem;
466 QStandardItem *_crossElementsDirItem;
469 QStandardItem *_explicitShapesDirItem;
470 QStandardItem *_implicitShapesDirItem;
471 QStandardItem *_cloudOfPointsDirItem;
479 QStandardItem *_groupDirItem;
482 QStandardItem *_lawDirItem;
483 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 _cylinderItemFlags;
493 Qt::ItemFlags _pipeItemFlags;
494 Qt::ItemFlags _elementsItemFlags;
495 Qt::ItemFlags _crossElementsItemFlags;
497 Qt::ItemFlags _groupItemFlags;
498 Qt::ItemFlags _lawItemFlags;
499 Qt::ItemFlags _propagationItemFlags;
504 class PatternDataModel : public QSortFilterProxyModel
507 PatternDataModel( QObject * parent = 0 );
508 virtual ~PatternDataModel();
510 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
511 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
513 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
516 HEXA_NS::Document* documentImpl();
517 QString documentEntry();
523 class PatternBuilderModel : public QSortFilterProxyModel
526 PatternBuilderModel( QObject * parent = 0 );
527 virtual ~PatternBuilderModel();
529 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
530 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
531 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
534 class PatternGeomModel : public QSortFilterProxyModel
537 PatternGeomModel( QObject* parent = 0);
538 virtual ~PatternGeomModel();
540 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
541 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
543 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
548 class AssociationsModel : public QSortFilterProxyModel
551 AssociationsModel( QObject * parent = 0 );
552 virtual ~AssociationsModel();
554 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
555 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
556 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
560 class GroupsModel : public QSortFilterProxyModel
563 GroupsModel( QObject * parent = 0 );
564 virtual ~GroupsModel();
566 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
567 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
568 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
570 QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
574 class MeshModel : public QSortFilterProxyModel
577 MeshModel( QObject * parent = 0 );
578 virtual ~MeshModel();
580 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
581 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
582 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
585 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;