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 "HEXABLOCKGUI_DocumentItem.hxx"
29 #include "HexDocument.hxx"
36 class DocumentModel : public QStandardItemModel
41 // enum EnumGroup { HexaCell, QuadCell, EdgeCell,
42 // HexaNode, QuadNode, EdgeNode, Vertex_Node};
43 typedef HEXA_NS::EnumGroup Group;
44 typedef HEXA_NS::KindLaw KindLaw;
50 QString subid; // sub-shape id
56 typedef QList<GeomObj> GeomObjList;
58 DocumentModel( HEXA_NS::Document* doc, const QString& entry, QObject * parent = 0 );
59 DocumentModel( int rows, int columns, QObject * parent = 0 );
61 virtual ~DocumentModel();
64 void setName(const QString& name);
66 void load( const QString& xmlFileName );
67 void save( const QString& xmlFileName );
74 void clearAssociation();
80 void fillAssociation();
84 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
88 void disallowEdition();
90 // void setDefaultSelection();
91 // void allowSelection();
92 void allowDataSelectionOnly();
93 void allowVertexSelectionOnly();
94 void allowEdgeSelectionOnly();
95 void allowQuadSelectionOnly();
96 void allowHexaSelectionOnly();
98 void allowVectorSelectionOnly();
99 void allowCylinderSelectionOnly();
100 void allowPipeSelectionOnly();
101 void allowElementsSelectionOnly();
102 void allowCrossElementsSelectionOnly();
104 void allowLawSelectionOnly();
107 void setName( const QModelIndex& iElt, const QString& name );
108 bool clearEltAssociations( const QModelIndex& iElt );
110 // ************ BUILD HEXABLOCK MODEL ************
111 QModelIndex addVertex( double x, double y, double z );
114 QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
115 QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
118 QModelIndex addQuadVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
119 const QModelIndex &i_v2, const QModelIndex &i_v3 );
120 QModelIndex addQuadEdges( const QModelIndex &i_e0, const QModelIndex &i_e1,
121 const QModelIndex &i_e2, const QModelIndex &i_e3 );
124 QModelIndex addHexaVertices( const QModelIndex &i_v0, const QModelIndex &i_v1,
125 const QModelIndex &i_v2, const QModelIndex &i_v3,
126 const QModelIndex &i_v4, const QModelIndex &i_v5,
127 const QModelIndex &i_v6, const QModelIndex &i_v7 );
128 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 );
130 QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
134 QModelIndex addVector( double dx, double dy, double dz );
135 QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
138 QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r, double h );
141 QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
145 QModelIndex makeCartesian( const QModelIndex& ivex,
146 const QModelIndex& ivecx, const QModelIndex& ivecy, const QModelIndex& ivecz,
147 long nx, long ny, long nz);
149 QModelIndex makeCartesian( const QModelIndex& ivex,
150 const QModelIndex& ivec,
151 int nx, int ny, int nz );
153 QModelIndex makeCylindrical( const QModelIndex& i_pt,
154 const QModelIndex& i_vx, const QModelIndex& i_vz,
155 double dr, double da, double dl,
156 long nr, long na, long nl,
159 QModelIndex makeCylindricals(
160 const QModelIndex& i_center, const QModelIndex& i_base, const QModelIndex& i_height,
161 QList< double> i_radius, QList<double> i_angles, QList<double> i_heights,
162 bool fill = false ); //NEW HEXA3
164 QModelIndex makeSpherical( const QModelIndex& i_v, const QModelIndex& i_vec, int nb, double k = 1 ); //CS_TO_DEL
166 QModelIndex makeSpherical( const QModelIndex& i_center, double rayon, int nb, double k = 1 );
169 QModelIndex makeCylinder( const QModelIndex& cyl, const QModelIndex& vec,
170 int nr, int na, int nl );
173 QModelIndex makePipe( const QModelIndex& pipe, const QModelIndex& vecx,
174 int nr, int na, int nl );
177 QModelIndex makeCylinders(const QModelIndex& cyl1, const QModelIndex& cyl2);
180 QModelIndex makePipes( const QModelIndex& pipe1, const QModelIndex& pipe2 );
184 QModelIndex makeRind( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
185 double radext, double radint, double radhole,
186 const QModelIndex& plorig,
187 int nrad, int nang, int nhaut ); //NEW HEXA3
189 QModelIndex makePartRind( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
190 double radext, double radint, double radhole,
191 const QModelIndex& plorig, double angle,
192 int nrad, int nang, int nhaut ); //NEW HEXA3
194 QModelIndex makeSphere( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
195 double radius, double radhole,
196 const QModelIndex& plorig,
197 int nrad, int nang, int nhaut ); //NEW HEXA3
199 QModelIndex makePartSphere( const QModelIndex& center, const QModelIndex& vecx, const QModelIndex& vecz,
200 double radius, double radhole,
201 const QModelIndex& plorig, double angle,
202 int nrad, int nang, int nhaut ); //NEW HEXA3
204 // ************ EDIT HEXABLOCK MODEL ************
206 bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
209 bool removeHexa( const QModelIndex& hexa );
210 bool removeConnectedHexa( const QModelIndex& hexa );
214 QModelIndex prismQuad( const QModelIndex& quad, const QModelIndex& dv, int nb);
215 QModelIndex prismQuads( const QModelIndexList& quads, const QModelIndex& dv, int nb);
219 QModelIndex joinQuad( const QModelIndex& start_q, const QModelIndex& dest_q,
220 const QModelIndex& v0, const QModelIndex& v1,
221 const QModelIndex& v2, const QModelIndex& v3,
225 QModelIndex joinQuads( const QModelIndexList& start_q, const QModelIndex& dest_q,
226 const QModelIndex& v0, const QModelIndex& v1,
227 const QModelIndex& v2, const QModelIndex& v3,
232 bool mergeVertices( const QModelIndex& va, const QModelIndex& vb );
233 bool mergeEdges( const QModelIndex& ea, const QModelIndex& eb,
234 const QModelIndex& v0, const QModelIndex& v1 );
235 bool mergeQuads( const QModelIndex& qa, const QModelIndex& qb,
236 const QModelIndex& v0, const QModelIndex& v1,
237 const QModelIndex& v2, const QModelIndex& v3 );
240 QModelIndex disconnectVertex( const QModelIndex& h, const QModelIndex& v );
241 QModelIndex disconnectEdge( const QModelIndex& h, const QModelIndex& e );
242 QModelIndex disconnectQuad( const QModelIndex& h, const QModelIndex& q );
243 QModelIndex disconnectEdges( const QModelIndexList& h, const QModelIndexList& e );
246 QModelIndex cutEdge( const QModelIndex &e, int nbcuts );
249 QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
250 QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
253 QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
256 QModelIndex makeSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
257 QModelIndex makeSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
258 QModelIndex makeSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
261 bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
264 bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
267 bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
270 bool performSymmetryPoint( const QModelIndex& elts, const QModelIndex& v );
271 bool performSymmetryLine( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
272 bool performSymmetryPlane( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec );
275 QModelIndex revolutionQuads( const QModelIndexList& startQuads, const QModelIndex& center,
276 const QModelIndex& vec_axis, const QList<double>& angles); //NEW HEXA3
278 QModelIndex replace( const QModelIndexList& quadsPattern,
279 const QModelIndex& p1, const QModelIndex& c1,
280 const QModelIndex& p2, const QModelIndex& c2,
281 const QModelIndex& p3, const QModelIndex& c3 ); //NEW HEXA3
287 // ************ ASSOCIATION ************
288 // elt is Vertex, Edge, Quad
289 void addAssociation( const QModelIndex& elt, const GeomObj& assoc );
290 QList<GeomObj> getAssociations( const QModelIndex& elt );
292 bool associateOpenedLine( const QModelIndexList& edges,
293 const GeomObjList& assocs,
297 bool associateClosedLine( const QModelIndex& vertex,
298 const QModelIndexList& edges,
299 const GeomObjList& assocs,
304 // ************ GROUPS ************
307 QModelIndex addGroup( const QString& name, Group kind );
310 bool removeGroup( const QModelIndex& grp );
313 QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
315 // 7.4 Boite: éditer un groupe
316 void setGroupName( const QModelIndex& grp, const QString& name );
317 bool addGroupElement( const QModelIndex& grp, const QModelIndex& elt );
318 bool removeGroupElement( const QModelIndex& grp, int nro ); //CS_TODO
319 bool clearGroupElement( const QModelIndex& grp );
322 // ************ LAWS ************
325 QModelIndex addLaw( const QString& name, int nbnodes );
327 // 8.2 Boite: créer une loi
331 // int setNodes (int nbre);
332 // int setCoefficient (double coeff);
333 // void setKind (KindLaw type);
336 bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
339 bool removeLaw( const QModelIndex& law );
341 // 8.3 Boite: éditer une loi
345 // 9.1 Boite: poser une loi de discrétisation sur une propagation
346 // int setLaw (Law* loi);
347 // void setWay (bool sens);
348 bool setPropagation( const QModelIndex& iPropagation, const QModelIndex& iLaw, bool way );
349 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
357 HEXA_NS::Document* documentImpl();
358 QString documentEntry();
359 // QModelIndex indexBy( int role, const QString& value );
362 void patternDataChanged();
363 void nameChanged(const QString& name);
366 QTemporaryFile *_hexaFile;
367 HEXA_NS::Document *_hexaDocument;
370 QMap<QString, QString> _assocName; // clé: id; valeur: nom
371 bool _disallowEdition;
374 QStandardItem *_vertexDirItem;
375 QStandardItem *_edgeDirItem;
376 QStandardItem *_quadDirItem;
377 QStandardItem *_hexaDirItem;
380 QStandardItem *_vectorDirItem;
381 QStandardItem *_cylinderDirItem;
382 QStandardItem *_pipeDirItem;
383 QStandardItem *_elementsDirItem;
384 QStandardItem *_crossElementsDirItem;
392 QStandardItem *_groupDirItem;
395 QStandardItem *_lawDirItem;
396 QStandardItem *_propagationDirItem;
399 Qt::ItemFlags _vertexItemFlags;
400 Qt::ItemFlags _edgeItemFlags;
401 Qt::ItemFlags _quadItemFlags;
402 Qt::ItemFlags _hexaItemFlags;
404 Qt::ItemFlags _vectorItemFlags;
405 Qt::ItemFlags _cylinderItemFlags;
406 Qt::ItemFlags _pipeItemFlags;
407 Qt::ItemFlags _elementsItemFlags;
408 Qt::ItemFlags _crossElementsItemFlags;
410 Qt::ItemFlags _groupItemFlags;
411 Qt::ItemFlags _lawItemFlags;
412 Qt::ItemFlags _propagationItemFlags;
418 class PatternDataModel : public QSortFilterProxyModel
421 PatternDataModel( QObject * parent = 0 );
422 virtual ~PatternDataModel();
424 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
425 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
427 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
430 HEXA_NS::Document* documentImpl();
431 QString documentEntry();
437 class PatternBuilderModel : public QSortFilterProxyModel
440 PatternBuilderModel( QObject * parent = 0 );
441 virtual ~PatternBuilderModel();
443 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
444 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
445 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
450 class AssociationsModel : public QSortFilterProxyModel
453 AssociationsModel( QObject * parent = 0 );
454 virtual ~AssociationsModel();
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;
462 class GroupsModel : public QSortFilterProxyModel
465 GroupsModel( QObject * parent = 0 );
466 virtual ~GroupsModel();
468 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
469 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
470 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
472 QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
476 class MeshModel : public QSortFilterProxyModel
479 MeshModel( QObject * parent = 0 );
480 virtual ~MeshModel();
482 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
483 virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
484 QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
487 QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;