Salome HOME
Merge from V6_main 13/12/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 #include "HexNewShape.hxx"
33
34 namespace HEXABLOCK
35 {
36   namespace GUI
37   {
38
39     class DocumentModel : public QStandardItemModel
40     {
41       Q_OBJECT
42     public:
43
44       // enum EnumGroup  { HexaCell, QuadCell, EdgeCell,
45       //                   HexaNode, QuadNode, EdgeNode, Vertex_Node};
46       typedef HEXA_NS::EnumGroup Group;
47       typedef HEXA_NS::KindLaw   KindLaw;
48
49       struct GeomObj
50       {
51         QString shapeName;
52         QString name;
53         QString subid; // sub-shape id
54         QString brep;
55         double  start;
56         double  end;
57       };
58
59       typedef QList<GeomObj> GeomObjList;
60
61       DocumentModel( HEXA_NS::Document* doc, const QString& entry, QObject * parent = 0 );
62       DocumentModel( int rows, int columns, QObject * parent = 0 );
63
64       virtual ~DocumentModel();
65
66
67       void setName(const QString& name);
68       QString getName();
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);
74       void updateData();
75       void refresh(); //refresh data
76       bool isEmpty() const;
77
78       void clearAll();
79       void clearData();
80       void clearBuilder();
81       void clearGeometry();
82       void clearAssociation();
83       void clearGroups();
84       void clearMesh();
85
86       void fillData();
87       void fillBuilder();
88       void fillGeometry();
89       void fillAssociation();
90       void fillGroups();
91       void fillMesh();
92
93       virtual Qt::ItemFlags flags(const QModelIndex &index) const;
94
95
96       void allowEdition();
97       void disallowEdition();
98
99       //         void setDefaultSelection();
100       //         void allowSelection();
101       void allowDataSelectionOnly();
102       void allowVertexSelectionOnly();
103       void allowEdgeSelectionOnly();
104       void allowQuadSelectionOnly();
105       void allowHexaSelectionOnly();
106
107       void allowVectorSelectionOnly();
108       void allowCylinderSelectionOnly();
109       void allowPipeSelectionOnly();
110       void allowElementsSelectionOnly();
111       void allowCrossElementsSelectionOnly();
112
113       void allowLawSelectionOnly();
114
115
116       HEXA_NS::EltBase* getHexaPtr(const QModelIndex& iElt);
117       template<typename T>
118       T getHexaPtr(QModelIndex iElt)
119       {
120         if (iElt.isValid())
121           return iElt.data( HEXA_DATA_ROLE ).value< T >();
122
123         return NULL;
124       }
125
126       int getNbrElt(HEXA_NS::EnumElt eltType);
127       int getNbrUsedElt(HEXA_NS::EnumElt eltType);
128       int getNbrUnusedElt(HEXA_NS::EnumElt eltType);
129
130       //associate a shape to the current document
131       bool addShape(TopoDS_Shape& forme, QString& shapeName);
132
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();
136       }
137
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();
141       }
142
143       //returns the document's shapes entries
144       QList<QString> getShapesEntries() const { return docShapesName.uniqueKeys(); }
145
146       //returns the associated geom index to the data index
147       HEXA_NS::SubShape* getGeomPtr(QString& id)
148       {
149           if (!shapeById.contains(id)) return NULL;
150           return shapeById[id];
151       }
152
153       void setGeomObjName(QString& studyEntry, QString& shapeName) {docShapesName[studyEntry] = shapeName;}
154       void setGeomObjEntry(QString& shapeName, QString& studyEntry) {docShapesEntry[shapeName] = studyEntry;}
155
156       void setName( const QModelIndex& iElt, const QString& name );
157       bool clearEltAssociations( const QModelIndex& iElt );
158       HEXA_NS::Hexa* getQuadHexa(HEXA_NS::Quad* quad);
159
160       //  ************  BUILD HEXABLOCK MODEL ************
161       QModelIndex addVertex( double x, double y, double z );
162
163       //
164       QModelIndex addEdgeVertices (const QModelIndex &i_v0, const QModelIndex &i_v1 );
165       QModelIndex addEdgeVector( const QModelIndex &i_v, const QModelIndex &i_vec );
166
167       //
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 );
172
173       //
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 );
179
180       QModelIndex addHexaQuads( const QModelIndexList &i_quads ); //NEW HEXA3
181
182
183       //
184       QModelIndex addVector( double dx, double dy, double dz );
185       QModelIndex addVectorVertices( const QModelIndex &i_v0, const QModelIndex &i_v1 );
186
187       //
188       QModelIndex addCylinder( const QModelIndex &iv, const QModelIndex &ivec, double r,  double h );
189
190       //
191       QModelIndex addPipe( const QModelIndex &iv, const QModelIndex &ivec, double ri, double re, double h );
192
193
194       //
195       QModelIndex makeCartesian( const QModelIndex& ivex,
196           const QModelIndex& ivecx, const QModelIndex& ivecy, const QModelIndex& ivecz,
197           long nx, long ny, long nz);
198
199       QModelIndex makeCartesian( const QModelIndex& ivex,
200           const QModelIndex& ivec,
201           int nx, int ny, int nz );
202
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,
207           bool fill  = false );
208
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
213
214       QModelIndex makeSpherical( const QModelIndex& i_v, const QModelIndex& i_vec, int nb, double k = 1 ); //CS_TO_DEL
215
216       QModelIndex makeSpherical( const QModelIndex& i_center, double rayon, int nb, double k = 1 );
217
218       //
219       QModelIndex makeCylinder( const QModelIndex& cyl, const QModelIndex& vec,
220           int nr, int na, int nl );
221
222       //
223       QModelIndex makePipe( const QModelIndex& pipe, const QModelIndex& vecx,
224           int nr, int na, int nl );
225
226       //
227       QModelIndex makeCylinders(const QModelIndex& cyl1, const QModelIndex& cyl2);
228
229       //
230       QModelIndex makePipes( const QModelIndex& pipe1, const QModelIndex& pipe2 );
231
232
233
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
238
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
243
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
248
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
253
254       // ************  EDIT HEXABLOCK MODEL ************
255
256       bool updateVertex( const QModelIndex& vertex, double x, double y, double z );
257
258       //
259       bool removeHexa( const QModelIndex& hexa );
260       bool removeConnectedHexa( const QModelIndex& hexa );
261
262
263       //
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);
267
268       //
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,
272           int nb );
273
274
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,
278           int nb );
279
280
281       //
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 );
288
289       //
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 );
294
295       //
296       QModelIndex cutEdge( const QModelIndex &e, int nbcuts );
297
298       //
299       QModelIndex makeTranslation( const QModelIndex& elts, const QModelIndex& vec );
300       QModelIndex makeScale( const QModelIndex& elts, const QModelIndex& v, double k );
301
302       //
303       QModelIndex makeRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
304
305       //
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 );
309
310       //
311       bool performTranslation( const QModelIndex& elts, const QModelIndex& vec );
312
313       //
314       bool performScale( const QModelIndex& elts, const QModelIndex& v, double k );
315
316       //
317       bool performRotation( const QModelIndex& elts, const QModelIndex& v, const QModelIndex& vec, double angle );
318
319       //
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 );
323
324
325       QModelIndex revolutionQuads( const QModelIndexList& startQuads, const QModelIndex& center,
326           const QModelIndex& vec_axis, const QList<double>& angles); //NEW HEXA3
327
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
332
333
334
335
336
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
341
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);
346
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);
351
352      //---------- perimees -------------
353       bool associateOpenedLine( const QModelIndexList& edges,
354           const GeomObjList&     assocs,
355           double pstart,
356           double pend );
357
358       bool associateClosedLine( const QModelIndex& vertex,
359           const QModelIndexList& edges,
360           const GeomObjList&     assocs,
361           double pstart,
362           bool   inv = false );
363       //-------------
364
365       bool associateOpenedLine( const QModelIndexList& edges,
366               HEXA_NS::NewShapes shapes,
367               HEXA_NS::IntVector subIds,
368               double pstart,
369               double pend );
370
371       bool associateClosedLine( const QModelIndex& vertex,
372               const QModelIndexList& edges,
373               HEXA_NS::NewShapes shapes,
374               HEXA_NS::IntVector subIds,
375               double pstart,
376               bool   inv = false );
377
378       void clearAssociation(HEXA_NS::EnumElt& eltType);
379
380
381       // ************  GROUPS  ************
382
383       //
384       QModelIndex addGroup( const QString& name, Group kind );
385
386       //
387       bool removeGroup( const QModelIndex& grp );
388
389       //
390       QModelIndexList getGroupElements( const QModelIndex& iGroup, Group& kind) const;
391
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 );
397
398
399       // ************  LAWS  ************
400
401       //
402       QModelIndex addLaw( const QString& name, int nbnodes );
403
404       // 8.2 Boite: créer une loi
405       // class Law
406       // {
407       // public:
408       // int     setNodes (int  nbre);
409       // int     setCoefficient (double coeff);
410       // void    setKind (KindLaw type);
411       // }
412
413       bool setLaw( const QModelIndex& ilaw, int nbnodes, double coeff, KindLaw type );
414
415       //
416       bool  removeLaw( const QModelIndex& law );
417
418       // 8.3 Boite: éditer une loi
419       // (idem création)
420
421       // 9 Discrétisation
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;
427
428       //
429       // 9.1 Boite: éditer
430       // (idem création)
431
432
433       // tools
434       HEXA_NS::Document* documentImpl();
435       QString            documentEntry();
436       //       QModelIndex        indexBy( int role, const QString& value );
437
438       signals:
439       void patternDataChanged();
440       void nameChanged(const QString& name);
441
442     private:
443       QTemporaryFile    *_hexaFile;
444       HEXA_NS::Document *_hexaDocument;
445       QString            _entry;
446
447       //geom
448       QMap<QString, QString> docShapesEntry;
449       QMap<QString, QString> docShapesName;
450       QMap<QString, HEXA_NS::SubShape*> shapeById;
451
452       QMap<QString, QString> _assocName; // clé: id; valeur: nom
453       bool              _disallowEdition;
454
455       //data
456       QStandardItem     *_vertexDirItem;
457       QStandardItem     *_edgeDirItem;
458       QStandardItem     *_quadDirItem;
459       QStandardItem     *_hexaDirItem;
460
461       //builder
462       QStandardItem     *_vectorDirItem;
463       QStandardItem     *_cylinderDirItem;
464       QStandardItem     *_pipeDirItem;
465       QStandardItem     *_elementsDirItem;
466       QStandardItem     *_crossElementsDirItem;
467
468       //geometry
469       QStandardItem     *_explicitShapesDirItem;
470       QStandardItem     *_implicitShapesDirItem;
471       QStandardItem     *_cloudOfPointsDirItem;
472
473
474       //association
475       // CS_TODO
476
477
478       // groups
479       QStandardItem     *_groupDirItem;
480
481       // law
482       QStandardItem     *_lawDirItem;
483       QStandardItem     *_propagationDirItem;
484
485
486       Qt::ItemFlags     _vertexItemFlags;
487       Qt::ItemFlags     _edgeItemFlags;
488       Qt::ItemFlags     _quadItemFlags;
489       Qt::ItemFlags     _hexaItemFlags;
490
491       Qt::ItemFlags     _vectorItemFlags;
492       Qt::ItemFlags     _cylinderItemFlags;
493       Qt::ItemFlags     _pipeItemFlags;
494       Qt::ItemFlags     _elementsItemFlags;
495       Qt::ItemFlags     _crossElementsItemFlags;
496
497       Qt::ItemFlags     _groupItemFlags;
498       Qt::ItemFlags     _lawItemFlags;
499       Qt::ItemFlags     _propagationItemFlags;
500
501     };
502
503
504     class  PatternDataModel : public QSortFilterProxyModel
505     {
506     public:
507       PatternDataModel( QObject * parent = 0 );
508       virtual ~PatternDataModel();
509
510       virtual Qt::ItemFlags flags(const QModelIndex &index) const;
511       virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
512
513       QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
514
515
516       HEXA_NS::Document* documentImpl();
517       QString            documentEntry();
518
519
520     };
521
522
523     class  PatternBuilderModel : public QSortFilterProxyModel
524     {
525     public:
526       PatternBuilderModel( QObject * parent = 0 );
527       virtual ~PatternBuilderModel();
528
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;
532     };
533
534     class PatternGeomModel : public QSortFilterProxyModel
535     {
536     public:
537         PatternGeomModel( QObject* parent = 0);
538         virtual ~PatternGeomModel();
539
540         virtual Qt::ItemFlags flags(const QModelIndex &index) const;
541         virtual QVariant headerData ( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;
542
543         QStandardItem * itemFromIndex ( const QModelIndex & index ) const;
544     };
545
546
547
548     class  AssociationsModel : public QSortFilterProxyModel
549     {
550     public:
551       AssociationsModel( QObject * parent = 0 );
552       virtual ~AssociationsModel();
553
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;
557     };
558
559
560     class  GroupsModel : public QSortFilterProxyModel
561     {
562     public:
563       GroupsModel( QObject * parent = 0 );
564       virtual ~GroupsModel();
565
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;
569
570       QModelIndexList getGroupElements( const QModelIndex& iGroup, DocumentModel::Group& kind ) const;
571     };
572
573
574     class  MeshModel : public QSortFilterProxyModel
575     {
576     public:
577       MeshModel( QObject * parent = 0 );
578       virtual ~MeshModel();
579
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;
583
584
585       QModelIndexList getPropagation( const QModelIndex& iPropagation ) const;
586     }; 
587
588
589
590
591   }
592 }
593
594 #endif