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"
38 class DocumentModel : public QStandardItemModel
43 // enum EnumGroup { HexaCell, QuadCell, EdgeCell,
44 // HexaNode, QuadNode, EdgeNode, Vertex_Node};
45 typedef HEXA_NS::EnumGroup Group;
46 typedef HEXA_NS::KindLaw KindLaw;
52 QString subid; // sub-shape id
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 void load( const QString& xmlFileName );
69 void save( const QString& xmlFileName );
70 struct GeomObj* convertToGeomObj(GEOM::GeomObjPtr geomObjPtr);
76 void clearAssociation();
82 void fillAssociation();
86 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
90 void disallowEdition();
92 // void setDefaultSelection();
93 // void allowSelection();
94 void allowDataSelectionOnly();
95 void allowVertexSelectionOnly();
96 void allowEdgeSelectionOnly();
97 void allowQuadSelectionOnly();
98 void allowHexaSelectionOnly();
100 void allowVectorSelectionOnly();
101 void allowCylinderSelectionOnly();
102 void allowPipeSelectionOnly();
103 void allowElementsSelectionOnly();
104 void allowCrossElementsSelectionOnly();
106 void allowLawSelectionOnly();
109 HEXA_NS::EltBase* getHexaPtr(const QModelIndex& iElt);
111 T getHexaPtr(QModelIndex iElt)
114 return iElt.data( HEXA_DATA_ROLE ).value< T >();
119 void setName( const QModelIndex& iElt, const QString& name );
120 bool clearEltAssociations( const QModelIndex& iElt );
121 HEXA_NS::Hexa* getQuadHexa(HEXA_NS::Quad* quad);
123 // ************ BUILD HEXABLOCK MODEL ************
124 QModelIndex addVertex( double x, double y, double z );
127 QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
128 QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
131 QModelIndex addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
132 const QModelIndex &i_v2, const QModelIndex &i_v3 );
133 QModelIndex addQuadEdges( const QModelIndex &i_e0, const QModelIndex &i_e1,
134 const QModelIndex &i_e2, const QModelIndex &i_e3 );
137 QModelIndex addHexaVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
138 const QModelIndex &i_v2, const QModelIndex &i_v3,
139 const QModelIndex &i_v4, const QModelIndex &i_v5,
140 const QModelIndex &i_v6, const QModelIndex &i_v7 );
141 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 );
143 QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
147 QModelIndex addVector( double dx, double dy, double dz );
148 QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
151 QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r, double h );
154 QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
158 QModelIndex makeCartesian( const QModelIndex& ivex,
159 const QModelIndex& ivecx, const QModelIndex& ivecy, const QModelIndex& ivecz,
160 long nx, long ny, long nz);
162 QModelIndex makeCartesian( const QModelIndex& ivex,
163 const QModelIndex& ivec,
164 int nx, int ny, int nz );
166 QModelIndex makeCylindrical( const QModelIndex& i_pt,
167 const QModelIndex& i_vx, const QModelIndex& i_vz,
168 double dr, double da, double dl,
169 long nr, long na, long nl,
172 QModelIndex makeCylindricals(
173 const QModelIndex& i_center, const QModelIndex& i_base, const QModelIndex& i_height,
174 QList< double> i_radius, QList<double> i_angles, QList<double> i_heights,
175 bool fill = false ); //NEW HEXA3
177 QModelIndex makeSpherical( const QModelIndex& i_v, const QModelIndex& i_vec, int nb, double k = 1 ); //CS_TO_DEL
179 QModelIndex makeSpherical( const QModelIndex& i_center, double rayon, int nb, double k = 1 );
182 QModelIndex makeCylinder( const QModelIndex& cyl, const QModelIndex& vec,
183 int nr, int na, int nl );
186 QModelIndex makePipe( const QModelIndex& pipe, const QModelIndex& vecx,
187 int nr, int na, int nl );
190 QModelIndex makeCylinders(const QModelIndex& cyl1, const QModelIndex& cyl2);
193 QModelIndex makePipes( const QModelIndex& pipe1, const QModelIndex& pipe2 );
197 QModelIndex makeRind( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
198 double radext, double radint, double radhole,
199 const QModelIndex& plorig,
200 int nrad, int nang, int nhaut ); //NEW HEXA3
202 QModelIndex makePartRind( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
203 double radext, double radint, double radhole,
204 const QModelIndex& plorig, double angle,
205 int nrad, int nang, int nhaut ); //NEW HEXA3
207 QModelIndex makeSphere( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
208 double radius, double radhole,
209 const QModelIndex& plorig,
210 int nrad, int nang, int nhaut ); //NEW HEXA3
212 QModelIndex makePartSphere( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
213 double radius, double radhole,
214 const QModelIndex& plorig, double angle,
215 int nrad, int nang, int nhaut ); //NEW HEXA3
217 // ************ EDIT HEXABLOCK MODEL ************
219 bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
222 bool removeHexa( const QModelIndex& hexa );
223 bool removeConnectedHexa( const QModelIndex& hexa );
227 QModelIndex prismQuad( const QModelIndex& quad, const QModelIndex& dv, int nb);
228 QModelIndex prismQuads( const QModelIndexList& quads, const QModelIndex& dv, int nb);
229 QModelIndex prismQuads( const QModelIndexList& quads, const QModelIndex& dv, std::vector<double>, int nb=0);
232 QModelIndex joinQuad( const QModelIndex& start_q, const QModelIndex& dest_q,
233 const QModelIndex& v0, const QModelIndex& v1,
234 const QModelIndex& v2, const QModelIndex& v3,
238 QModelIndex joinQuads( const QModelIndexList& start_q, const QModelIndex& dest_q,
239 const QModelIndex& v0, const QModelIndex& v1,
240 const QModelIndex& v2, const QModelIndex& v3,
245 bool mergeVertices( const QModelIndex& va, const QModelIndex& vb );
246 bool mergeEdges( const QModelIndex& ea, const QModelIndex& eb,
247 const QModelIndex& v0, const QModelIndex& v1 );
248 bool mergeQuads( const QModelIndex& qa, const QModelIndex& qb,
249 const QModelIndex& v0, const QModelIndex& v1,
250 const QModelIndex& v2, const QModelIndex& v3 );
253 QModelIndex disconnectVertex( const QModelIndex& h, const QModelIndex& v );
254 QModelIndex disconnectEdge( const QModelIndex& h, const QModelIndex& e );
255 QModelIndex disconnectQuad( const QModelIndex& h, const QModelIndex& q );
256 QModelIndex disconnectEdges( const QModelIndexList& h, const QModelIndexList& e );
259 QModelIndex cutEdge( const QModelIndex &e, int nbcuts );
262 QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
263 QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
266 QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
269 QModelIndex makeSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
270 QModelIndex makeSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
271 QModelIndex makeSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
274 bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
277 bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
280 bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
283 bool performSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
284 bool performSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
285 bool performSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
288 QModelIndex revolutionQuads( const QModelIndexList& startQuads, const QModelIndex& center,
289 const QModelIndex& vec_axis, const QList<double>& angles); //NEW HEXA3
291 QModelIndex replace( const QModelIndexList& quadsPattern,
292 const QModelIndex& p1, const QModelIndex& c1,
293 const QModelIndex& p2, const QModelIndex& c2,
294 const QModelIndex& p3, const QModelIndex& c3 ); //NEW HEXA3
300 // ************ ASSOCIATION ************
301 // elt is Vertex, Edge, Quad
302 void addAssociation( const QModelIndex& elt, const GeomObj& assoc );
303 QList<GeomObj> getAssociations( const QModelIndex& elt );
305 bool associateOpenedLine( const QModelIndexList& edges,
306 const GeomObjList& assocs,
310 bool associateClosedLine( const QModelIndex& vertex,
311 const QModelIndexList& edges,
312 const GeomObjList& assocs,
317 // ************ GROUPS ************
320 QModelIndex addGroup( const QString& name, Group kind );
323 bool removeGroup( const QModelIndex& grp );
326 QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
328 // 7.4 Boite: éditer un groupe
329 void setGroupName( const QModelIndex& grp, const QString& name );
330 bool addGroupElement( const QModelIndex& grp, const QModelIndex& elt );
331 bool removeGroupElement( const QModelIndex& grp, int nro ); //CS_TODO
332 bool clearGroupElement( const QModelIndex& grp );
335 // ************ LAWS ************
338 QModelIndex addLaw( const QString& name, int nbnodes );
340 // 8.2 Boite: créer une loi
344 // int setNodes (int nbre);
345 // int setCoefficient (double coeff);
346 // void setKind (KindLaw type);
349 bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
352 bool removeLaw( const QModelIndex& law );
354 // 8.3 Boite: éditer une loi
358 // 9.1 Boite: poser une loi de discrétisation sur une propagation
359 // int setLaw (Law* loi);
360 // void setWay (bool sens);
361 bool setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way );
362 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
370 HEXA_NS::Document* documentImpl();
371 QString documentEntry();
372 // QModelIndex indexBy( int role, const QString& value );
375 void patternDataChanged();
376 void nameChanged(const QString& name);
379 QTemporaryFile *_hexaFile;
380 HEXA_NS::Document *_hexaDocument;
383 QMap<QString, QString> _assocName; // clé: id; valeur: nom
384 bool _disallowEdition;
387 QStandardItem *_vertexDirItem;
388 QStandardItem *_edgeDirItem;
389 QStandardItem *_quadDirItem;
390 QStandardItem *_hexaDirItem;
393 QStandardItem *_vectorDirItem;
394 QStandardItem *_cylinderDirItem;
395 QStandardItem *_pipeDirItem;
396 QStandardItem *_elementsDirItem;
397 QStandardItem *_crossElementsDirItem;
405 QStandardItem *_groupDirItem;
408 QStandardItem *_lawDirItem;
409 QStandardItem *_propagationDirItem;
412 Qt::ItemFlags _vertexItemFlags;
413 Qt::ItemFlags _edgeItemFlags;
414 Qt::ItemFlags _quadItemFlags;
415 Qt::ItemFlags _hexaItemFlags;
417 Qt::ItemFlags _vectorItemFlags;
418 Qt::ItemFlags _cylinderItemFlags;
419 Qt::ItemFlags _pipeItemFlags;
420 Qt::ItemFlags _elementsItemFlags;
421 Qt::ItemFlags _crossElementsItemFlags;
423 Qt::ItemFlags _groupItemFlags;
424 Qt::ItemFlags _lawItemFlags;
425 Qt::ItemFlags _propagationItemFlags;
431 class PatternDataModel : public QSortFilterProxyModel
434 PatternDataModel( QObject * parent = 0 );
435 virtual ~PatternDataModel();
437 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
438 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
440 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
443 HEXA_NS::Document* documentImpl();
444 QString documentEntry();
450 class PatternBuilderModel : public QSortFilterProxyModel
453 PatternBuilderModel( QObject * parent = 0 );
454 virtual ~PatternBuilderModel();
456 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
457 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
458 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
463 class AssociationsModel : public QSortFilterProxyModel
466 AssociationsModel( QObject * parent = 0 );
467 virtual ~AssociationsModel();
469 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
470 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
471 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
475 class GroupsModel : public QSortFilterProxyModel
478 GroupsModel( QObject * parent = 0 );
479 virtual ~GroupsModel();
481 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
482 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
483 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
485 QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
489 class MeshModel : public QSortFilterProxyModel
492 MeshModel( QObject * parent = 0 );
493 virtual ~MeshModel();
495 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
496 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
497 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
500 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;