]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/HEXABLOCKGUI_DocumentModel.hxx
Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentModel.hxx
1 // Copyright (C) 2009-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef _HEXABLOCKGUI_DOCUMENTMODEL_HXX_
21 #define _HEXABLOCKGUI_DOCUMENTMODEL_HXX_
22
23
24 #include <QTemporaryFile>
25 #include <QStandardItemModel>
26 #include <QSortFilterProxyModel>
27
28 #include "HEXABLOCKGUI_DocumentItem.hxx"
29 #include "HexDocument.hxx"
30
31 namespace HEXABLOCK
32 {
33   namespace GUI
34   {
35
36     class DocumentModel : public QStandardItemModel
37     {
38       Q_OBJECT
39       public:
40
41         // enum EnumGroup  { HexaCell, QuadCell, EdgeCell, 
42         //                   HexaNode, QuadNode, EdgeNode, Vertex_Node};
43         typedef HEXA_NS::EnumGroup Group;
44         typedef HEXA_NS::KindLaw   KindLaw;
45
46         struct GeomObj
47         {
48           QString name;
49           QString entry;
50           QString subid; // sub-shape id
51           QString brep;
52           double  start;
53           double  end;
54         };
55
56         typedef QList<GeomObj> GeomObjList;
57
58         DocumentModel( HEXA_NS::Document* doc, const QString& entry, QObject * parent = 0 );
59         DocumentModel( int rows, int columns, QObject * parent = 0 );
60
61         virtual ~DocumentModel();
62
63
64         void setName(const QString& name);
65         QString getName();
66         void load( const QString& xmlFileName );
67         void save( const QString& xmlFileName );
68
69         void updateData();
70
71         void clearAll();
72         void clearData();
73         void clearBuilder();
74         void clearAssociation();
75         void clearGroups();
76         void clearMesh();
77
78         void fillData();
79         void fillBuilder();
80         void fillAssociation();
81         void fillGroups();
82         void fillMesh();
83
84         virtual Qt::ItemFlags flags(const QModelIndex &index) const;
85
86
87         void allowEdition();
88         void disallowEdition();
89
90 //         void setDefaultSelection();
91 //         void allowSelection();
92         void allowDataSelectionOnly();
93         void allowVertexSelectionOnly();
94         void allowEdgeSelectionOnly();
95         void allowQuadSelectionOnly();
96         void allowHexaSelectionOnly();
97
98         void allowVectorSelectionOnly();
99         void allowCylinderSelectionOnly();
100         void allowPipeSelectionOnly();
101         void allowElementsSelectionOnly();
102         void allowCrossElementsSelectionOnly();
103
104         void allowLawSelectionOnly();
105
106
107         void setName( const QModelIndex& iElt, const QString& name );
108         bool clearEltAssociations( const QModelIndex& iElt );
109
110         //  ************  BUILD HEXABLOCK MODEL ************
111         QModelIndex addVertex( double x, double y, double z );
112
113         //
114         QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
115         QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
116
117         //
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 );
122
123         //
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 );
129
130         QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
131
132
133         //
134         QModelIndex addVector( double dx, double dy, double dz );
135         QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
136
137         //
138         QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r,  double h );
139         
140         //
141         QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
142
143
144         // 
145         QModelIndex makeCartesian( const QModelIndex& ivex,
146                                    const QModelIndex& ivecx, const QModelIndex& ivecy, const QModelIndex& ivecz,
147                                    long nx, long ny, long nz);
148
149         QModelIndex makeCartesian( const QModelIndex& ivex,
150                                    const QModelIndex& ivec,
151                                    int nx, int ny, int nz );
152
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,
157                                      bool fill  = false );
158
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
163
164         QModelIndex makeSpherical( const QModelIndex& i_v, const QModelIndex& i_vec, int nb, double k = 1 ); //CS_TO_DEL
165
166         QModelIndex makeSpherical( const QModelIndex& i_center, double rayon, int nb, double k = 1 );
167
168         //
169         QModelIndex makeCylinder( const QModelIndex& cyl, const QModelIndex& vec,
170                                   int nr, int na, int nl );
171
172         //
173         QModelIndex makePipe( const QModelIndex& pipe, const QModelIndex& vecx, 
174                               int nr, int na, int nl );
175
176         //
177         QModelIndex makeCylinders(const QModelIndex& cyl1, const QModelIndex& cyl2);
178
179         //
180         QModelIndex makePipes( const QModelIndex& pipe1, const QModelIndex& pipe2 );
181
182
183     
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
188
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
193
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
198
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
203
204         // ************  EDIT HEXABLOCK MODEL ************
205
206         bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
207
208         //
209         bool removeHexa( const QModelIndex& hexa );
210         bool removeConnectedHexa( const QModelIndex& hexa );
211
212
213         //
214         QModelIndex prismQuad( const QModelIndex& quad, const QModelIndex& dv, int nb);
215         QModelIndex prismQuads( const QModelIndexList& quads, const QModelIndex& dv, int nb);
216
217
218         //
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,
222                               int nb );
223
224
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,
228                                int nb );
229
230
231         //
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 );
238
239         //
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 );
244
245         //
246         QModelIndex cutEdge( const QModelIndex &e, int nbcuts );
247
248         //
249         QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
250         QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
251
252         //
253         QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
254
255         //
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 );
259
260         //
261         bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
262
263         //
264         bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
265
266         //
267         bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
268
269         //
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 );
273
274
275         QModelIndex revolutionQuads( const QModelIndexList& startQuads, const QModelIndex& center, 
276                                      const QModelIndex& vec_axis, const QList<double>& angles); //NEW HEXA3
277
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
282
283
284
285
286
287         // ************  ASSOCIATION ************
288         // elt is Vertex, Edge, Quad
289         void addAssociation( const QModelIndex& elt, const GeomObj& assoc );
290         QList<GeomObj> getAssociations( const QModelIndex& elt );
291
292         bool associateOpenedLine( const QModelIndexList& edges,
293                                   const GeomObjList&     assocs,
294                                   double pstart,
295                                   double pend );
296
297         bool associateClosedLine( const QModelIndex& vertex, 
298                                   const QModelIndexList& edges,
299                                   const GeomObjList&     assocs,
300                                   double pstart, 
301                                   bool   inv = false );
302
303
304         // ************  GROUPS  ************
305
306         //
307         QModelIndex addGroup( const QString& name, Group kind );
308
309         //
310         bool removeGroup( const QModelIndex& grp );
311
312         //
313         QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
314
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 );
320
321
322         // ************  LAWS  ************
323
324         //
325         QModelIndex addLaw( const QString& name, int nbnodes );
326
327 // 8.2 Boite: créer une loi 
328 // class Law 
329 // {
330 // public:
331 // int     setNodes (int  nbre);
332 // int     setCoefficient (double coeff);
333 // void    setKind (KindLaw type);
334 // }
335
336         bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
337
338         // 
339         bool  removeLaw( const QModelIndex& law );
340
341         // 8.3 Boite: éditer une loi 
342         // (idem création)
343
344 // 9 Discrétisation
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;
350
351 // 
352 // 9.1 Boite: éditer 
353 // (idem création)
354
355
356       // tools
357       HEXA_NS::Document* documentImpl();
358       QString            documentEntry();
359 //       QModelIndex        indexBy( int role, const QString& value );
360
361       signals:
362         void patternDataChanged();
363         void nameChanged(const QString& name);
364         
365       private:
366         QTemporaryFile    *_hexaFile;
367         HEXA_NS::Document *_hexaDocument;
368         QString            _entry;
369
370         QMap<QString, QString> _assocName; // clé: id; valeur: nom
371         bool              _disallowEdition;
372
373         //data
374         QStandardItem     *_vertexDirItem;
375         QStandardItem     *_edgeDirItem;
376         QStandardItem     *_quadDirItem;
377         QStandardItem     *_hexaDirItem;
378
379         //builder
380         QStandardItem     *_vectorDirItem;
381         QStandardItem     *_cylinderDirItem;
382         QStandardItem     *_pipeDirItem;
383         QStandardItem     *_elementsDirItem;
384         QStandardItem     *_crossElementsDirItem;
385
386       
387         //association
388         // CS_TODO
389
390
391         // groups
392         QStandardItem     *_groupDirItem;
393
394         // law
395         QStandardItem     *_lawDirItem;
396         QStandardItem     *_propagationDirItem;
397
398
399         Qt::ItemFlags     _vertexItemFlags;
400         Qt::ItemFlags     _edgeItemFlags;
401         Qt::ItemFlags     _quadItemFlags;
402         Qt::ItemFlags     _hexaItemFlags;
403
404         Qt::ItemFlags     _vectorItemFlags;
405         Qt::ItemFlags     _cylinderItemFlags;
406         Qt::ItemFlags     _pipeItemFlags;
407         Qt::ItemFlags     _elementsItemFlags;
408         Qt::ItemFlags     _crossElementsItemFlags;
409
410         Qt::ItemFlags     _groupItemFlags;
411         Qt::ItemFlags     _lawItemFlags;
412         Qt::ItemFlags     _propagationItemFlags;
413
414     };
415
416
417
418     class  PatternDataModel : public QSortFilterProxyModel
419     {
420       public:
421         PatternDataModel( QObject * parent = 0 );
422         virtual ~PatternDataModel();
423
424         virtual Qt::ItemFlags flags(const QModelIndex &index) const;
425         virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
426
427         QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
428
429
430         HEXA_NS::Document* documentImpl();
431         QString            documentEntry();
432
433
434     };
435
436
437     class  PatternBuilderModel : public QSortFilterProxyModel
438     {
439       public:
440         PatternBuilderModel( QObject * parent = 0 );
441         virtual ~PatternBuilderModel();
442
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;
446     };
447
448
449
450     class  AssociationsModel : public QSortFilterProxyModel
451     {
452       public:
453         AssociationsModel( QObject * parent = 0 );
454         virtual ~AssociationsModel();
455
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;
459     };
460
461
462     class  GroupsModel : public QSortFilterProxyModel
463     {
464       public:
465         GroupsModel( QObject * parent = 0 );
466         virtual ~GroupsModel();
467
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;
471
472         QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
473      };
474
475
476     class  MeshModel : public QSortFilterProxyModel
477     {
478       public:
479         MeshModel( QObject * parent = 0 );
480         virtual ~MeshModel();
481
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;
485
486
487         QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
488     }; 
489
490
491
492
493   }
494 }
495
496 #endif