]> SALOME platform Git repositories - modules/hexablock.git/blob - src/HEXABLOCKGUI/HEXABLOCKGUI_DocumentModel.hxx
Salome HOME
Merge from V6_main (04/10/2012)
[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 "GEOM_GenericObjPtr.h"
29
30 #include "HEXABLOCKGUI_DocumentItem.hxx"
31 #include "HexDocument.hxx"
32
33 namespace HEXABLOCK
34 {
35   namespace GUI
36   {
37
38     class DocumentModel : public QStandardItemModel
39     {
40       Q_OBJECT
41       public:
42
43         // enum EnumGroup  { HexaCell, QuadCell, EdgeCell, 
44         //                   HexaNode, QuadNode, EdgeNode, Vertex_Node};
45         typedef HEXA_NS::EnumGroup Group;
46         typedef HEXA_NS::KindLaw   KindLaw;
47
48         struct GeomObj
49         {
50           QString name;
51           QString entry;
52           QString subid; // sub-shape id
53           QString brep;
54           double  start;
55           double  end;
56         };
57
58         typedef QList<GeomObj> GeomObjList;
59
60         DocumentModel( HEXA_NS::Document* doc, const QString& entry, QObject * parent = 0 );
61         DocumentModel( int rows, int columns, QObject * parent = 0 );
62
63         virtual ~DocumentModel();
64
65
66         void setName(const QString& name);
67         QString getName();
68         void load( const QString& xmlFileName );
69         void save( const QString& xmlFileName );
70         struct GeomObj* convertToGeomObj(GEOM::GeomObjPtr geomObjPtr);
71         void updateData();
72
73         void clearAll();
74         void clearData();
75         void clearBuilder();
76         void clearAssociation();
77         void clearGroups();
78         void clearMesh();
79
80         void fillData();
81         void fillBuilder();
82         void fillAssociation();
83         void fillGroups();
84         void fillMesh();
85
86         virtual Qt::ItemFlags flags(const QModelIndex &index) const;
87
88
89         void allowEdition();
90         void disallowEdition();
91
92 //         void setDefaultSelection();
93 //         void allowSelection();
94         void allowDataSelectionOnly();
95         void allowVertexSelectionOnly();
96         void allowEdgeSelectionOnly();
97         void allowQuadSelectionOnly();
98         void allowHexaSelectionOnly();
99
100         void allowVectorSelectionOnly();
101         void allowCylinderSelectionOnly();
102         void allowPipeSelectionOnly();
103         void allowElementsSelectionOnly();
104         void allowCrossElementsSelectionOnly();
105
106         void allowLawSelectionOnly();
107
108
109         HEXA_NS::EltBase* getHexaPtr(const QModelIndex& iElt);
110         template<typename T>
111         T getHexaPtr(QModelIndex iElt)
112         {
113                 if (iElt.isValid())
114                         return iElt.data( HEXA_DATA_ROLE ).value< T >();
115
116                 return NULL;
117         }
118
119         void setName( const QModelIndex& iElt, const QString& name );
120         bool clearEltAssociations( const QModelIndex& iElt );
121         HEXA_NS::Hexa* getQuadHexa(HEXA_NS::Quad* quad);
122
123         //  ************  BUILD HEXABLOCK MODEL ************
124         QModelIndex addVertex( double x, double y, double z );
125
126         //
127         QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
128         QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
129
130         //
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 );
135
136         //
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 );
142
143         QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
144
145
146         //
147         QModelIndex addVector( double dx, double dy, double dz );
148         QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
149
150         //
151         QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r,  double h );
152         
153         //
154         QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
155
156
157         // 
158         QModelIndex makeCartesian( const QModelIndex& ivex,
159                                    const QModelIndex& ivecx, const QModelIndex& ivecy, const QModelIndex& ivecz,
160                                    long nx, long ny, long nz);
161
162         QModelIndex makeCartesian( const QModelIndex& ivex,
163                                    const QModelIndex& ivec,
164                                    int nx, int ny, int nz );
165
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,
170                                      bool fill  = false );
171
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
176
177         QModelIndex makeSpherical( const QModelIndex& i_v, const QModelIndex& i_vec, int nb, double k = 1 ); //CS_TO_DEL
178
179         QModelIndex makeSpherical( const QModelIndex& i_center, double rayon, int nb, double k = 1 );
180
181         //
182         QModelIndex makeCylinder( const QModelIndex& cyl, const QModelIndex& vec,
183                                   int nr, int na, int nl );
184
185         //
186         QModelIndex makePipe( const QModelIndex& pipe, const QModelIndex& vecx, 
187                               int nr, int na, int nl );
188
189         //
190         QModelIndex makeCylinders(const QModelIndex& cyl1, const QModelIndex& cyl2);
191
192         //
193         QModelIndex makePipes( const QModelIndex& pipe1, const QModelIndex& pipe2 );
194
195
196     
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
201
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
206
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
211
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
216
217         // ************  EDIT HEXABLOCK MODEL ************
218
219         bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
220
221         //
222         bool removeHexa( const QModelIndex& hexa );
223         bool removeConnectedHexa( const QModelIndex& hexa );
224
225
226         //
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);
230
231         //
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,
235                               int nb );
236
237
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,
241                                int nb );
242
243
244         //
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 );
251
252         //
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 );
257
258         //
259         QModelIndex cutEdge( const QModelIndex &e, int nbcuts );
260
261         //
262         QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
263         QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
264
265         //
266         QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
267
268         //
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 );
272
273         //
274         bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
275
276         //
277         bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
278
279         //
280         bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
281
282         //
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 );
286
287
288         QModelIndex revolutionQuads( const QModelIndexList& startQuads, const QModelIndex& center, 
289                                      const QModelIndex& vec_axis, const QList<double>& angles); //NEW HEXA3
290
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
295
296
297
298
299
300         // ************  ASSOCIATION ************
301         // elt is Vertex, Edge, Quad
302         void addAssociation( const QModelIndex& elt, const GeomObj& assoc );
303         QList<GeomObj> getAssociations( const QModelIndex& elt );
304
305         bool associateOpenedLine( const QModelIndexList& edges,
306                                   const GeomObjList&     assocs,
307                                   double pstart,
308                                   double pend );
309
310         bool associateClosedLine( const QModelIndex& vertex, 
311                                   const QModelIndexList& edges,
312                                   const GeomObjList&     assocs,
313                                   double pstart, 
314                                   bool   inv = false );
315
316
317         // ************  GROUPS  ************
318
319         //
320         QModelIndex addGroup( const QString& name, Group kind );
321
322         //
323         bool removeGroup( const QModelIndex& grp );
324
325         //
326         QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
327
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 );
333
334
335         // ************  LAWS  ************
336
337         //
338         QModelIndex addLaw( const QString& name, int nbnodes );
339
340 // 8.2 Boite: créer une loi 
341 // class Law 
342 // {
343 // public:
344 // int     setNodes (int  nbre);
345 // int     setCoefficient (double coeff);
346 // void    setKind (KindLaw type);
347 // }
348
349         bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
350
351         // 
352         bool  removeLaw( const QModelIndex& law );
353
354         // 8.3 Boite: éditer une loi 
355         // (idem création)
356
357 // 9 Discrétisation
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;
363
364 // 
365 // 9.1 Boite: éditer 
366 // (idem création)
367
368
369       // tools
370       HEXA_NS::Document* documentImpl();
371       QString            documentEntry();
372 //       QModelIndex        indexBy( int role, const QString& value );
373
374       signals:
375         void patternDataChanged();
376         void nameChanged(const QString& name);
377         
378       private:
379         QTemporaryFile    *_hexaFile;
380         HEXA_NS::Document *_hexaDocument;
381         QString            _entry;
382
383         QMap<QString, QString> _assocName; // clé: id; valeur: nom
384         bool              _disallowEdition;
385
386         //data
387         QStandardItem     *_vertexDirItem;
388         QStandardItem     *_edgeDirItem;
389         QStandardItem     *_quadDirItem;
390         QStandardItem     *_hexaDirItem;
391
392         //builder
393         QStandardItem     *_vectorDirItem;
394         QStandardItem     *_cylinderDirItem;
395         QStandardItem     *_pipeDirItem;
396         QStandardItem     *_elementsDirItem;
397         QStandardItem     *_crossElementsDirItem;
398
399       
400         //association
401         // CS_TODO
402
403
404         // groups
405         QStandardItem     *_groupDirItem;
406
407         // law
408         QStandardItem     *_lawDirItem;
409         QStandardItem     *_propagationDirItem;
410
411
412         Qt::ItemFlags     _vertexItemFlags;
413         Qt::ItemFlags     _edgeItemFlags;
414         Qt::ItemFlags     _quadItemFlags;
415         Qt::ItemFlags     _hexaItemFlags;
416
417         Qt::ItemFlags     _vectorItemFlags;
418         Qt::ItemFlags     _cylinderItemFlags;
419         Qt::ItemFlags     _pipeItemFlags;
420         Qt::ItemFlags     _elementsItemFlags;
421         Qt::ItemFlags     _crossElementsItemFlags;
422
423         Qt::ItemFlags     _groupItemFlags;
424         Qt::ItemFlags     _lawItemFlags;
425         Qt::ItemFlags     _propagationItemFlags;
426
427     };
428
429
430
431     class  PatternDataModel : public QSortFilterProxyModel
432     {
433       public:
434         PatternDataModel( QObject * parent = 0 );
435         virtual ~PatternDataModel();
436
437         virtual Qt::ItemFlags flags(const QModelIndex &index) const;
438         virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
439
440         QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
441
442
443         HEXA_NS::Document* documentImpl();
444         QString            documentEntry();
445
446
447     };
448
449
450     class  PatternBuilderModel : public QSortFilterProxyModel
451     {
452       public:
453         PatternBuilderModel( QObject * parent = 0 );
454         virtual ~PatternBuilderModel();
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
463     class  AssociationsModel : public QSortFilterProxyModel
464     {
465       public:
466         AssociationsModel( QObject * parent = 0 );
467         virtual ~AssociationsModel();
468
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;
472     };
473
474
475     class  GroupsModel : public QSortFilterProxyModel
476     {
477       public:
478         GroupsModel( QObject * parent = 0 );
479         virtual ~GroupsModel();
480
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;
484
485         QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
486      };
487
488
489     class  MeshModel : public QSortFilterProxyModel
490     {
491       public:
492         MeshModel( QObject * parent = 0 );
493         virtual ~MeshModel();
494
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;
498
499
500         QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
501     }; 
502
503
504
505
506   }
507 }
508
509 #endif