Salome HOME
7016d470447314e6a097779e18c06697ad3856bb
[modules/hexablock.git] / src / HEXABLOCKGUI / HEXABLOCKGUI_DocumentItem.cxx
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
21 #include "HEXABLOCKGUI_DocumentItem.hxx"
22 #include "HexShape.hxx"
23
24 #include <inttypes.h>
25
26 /*
27 #include <QVariant>*/
28
29
30 //#define _DEVDEBUG_
31
32
33 using namespace std;
34 using namespace HEXABLOCK::GUI;
35
36
37 // ----------------------- VERTEX
38
39 VertexItem::VertexItem( HEXA_NS::Vertex* hexaVertex ):
40   QStandardItem(),
41   _hexaVertex( hexaVertex )
42 {
43 //   char pName[12];
44   QString name = _hexaVertex->getName(/*pName*/);
45 //   QString docEntry = model()->invisibleRootItem()->data(HEXA_ENTRY_ROLE).toString();
46   setText(name);
47 //   setFlags( Qt::ItemIsSelectable | Qt::ItemIsEnabled );//Qt::ItemIsEditable);
48   setData( VERTEX_TREE, HEXA_TREE_ROLE );
49   setData( QString::number( reinterpret_cast<intptr_t>(_hexaVertex) ), HEXA_ENTRY_ROLE ); //_hexaVertex->dad()
50
51   HEXA_NS::Shape* assoc = hexaVertex->getAssociation();
52   if ( assoc ){
53     QString entry = QString(assoc->ident.c_str());
54     setData( entry + ";" , HEXA_ASSOC_ENTRY_ROLE );
55   }
56 }
57
58 int VertexItem::type() const
59 {
60   return VERTEXITEM;
61 }
62
63
64
65 QVariant VertexItem::data( int role ) const
66 {
67         if ( role == HEXA_DATA_ROLE ){
68                 return QVariant::fromValue( _hexaVertex );
69         } else if (role == Qt::ForegroundRole ) {
70                 HEXA_NS::Shape* assoc = _hexaVertex->getAssociation();
71                 if ( assoc )
72                         return QColor(Qt::darkGreen);
73                 else
74                         return QColor(Qt::black);
75         } else {
76                 return QStandardItem::data( role );
77         }
78 }
79
80 void VertexItem::setData ( const QVariant & value, int role )
81 {
82     if ( role == HEXA_DATA_ROLE ){
83       _hexaVertex = value.value<HEXA_NS::Vertex*>();
84       emitDataChanged ();
85     } else {
86 //       std::cout << " VertexItem::setData( " << role << ", "<< value.toString().toStdString() << " )" <<std::endl;
87       QStandardItem::setData ( value, role );
88     }
89 }
90
91
92
93 // ----------------------- EDGE
94 EdgeItem::EdgeItem( HEXA_NS::Edge* hexaEdge ):
95   QStandardItem(),
96   _hexaEdge( hexaEdge )
97 {
98 //   char pName[12];
99 //   QString name = _hexaEdge->getName(pName);
100   QString name = _hexaEdge->getName();
101 //   std::cout << "EdgeItem name : "<<  name.toStdString() << std::endl;
102   setText(name);
103   setData( EDGE_TREE, HEXA_TREE_ROLE );
104   setData( QString::number( reinterpret_cast<intptr_t>(_hexaEdge) ), HEXA_ENTRY_ROLE );
105
106   QString entries, entry;
107   const HEXA_NS::Shapes& assocs = hexaEdge->getAssociations();
108   for( HEXA_NS::Shapes::const_iterator anAssoc = assocs.begin(); anAssoc != assocs.end(); ++anAssoc ){
109     entry = (*anAssoc)->ident.c_str();
110     entries += entry + ";";
111   }
112   if ( !entries.isEmpty() )
113     setData( entries, HEXA_ASSOC_ENTRY_ROLE );
114
115 }
116
117
118 int EdgeItem::type() const
119 {
120   return EDGEITEM;
121 }
122
123 QVariant EdgeItem::data( int role ) const
124 {
125         if ( role == HEXA_DATA_ROLE ){
126                 return QVariant::fromValue( _hexaEdge );
127         } else if (role == Qt::ForegroundRole ) {
128                 const HEXA_NS::Shapes& assocs = _hexaEdge->getAssociations();
129                 if ( assocs.size()>0 )
130                         return QColor(Qt::darkGreen);
131                 else
132                         return QColor(Qt::black);
133         } else {
134                 return QStandardItem::data( role );
135         }
136 }
137
138 void EdgeItem::setData ( const QVariant & value, int role )
139 {
140     if ( role == HEXA_DATA_ROLE ){
141       _hexaEdge = value.value<HEXA_NS::Edge*>();
142       emitDataChanged ();
143     } else {
144       QStandardItem::setData ( value, role );
145     }
146 }
147
148
149
150
151 // ----------------------- QUAD
152 QuadItem::QuadItem( HEXA_NS::Quad* hexaQuad ):
153   QStandardItem(),
154   _hexaQuad( hexaQuad )
155 {
156 //   char pName[12];
157   QString name = _hexaQuad->getName(/*pName*/);
158   setText(name);
159   setData( QUAD_TREE, HEXA_TREE_ROLE );
160   setData( QString::number(reinterpret_cast<intptr_t>(_hexaQuad)), HEXA_ENTRY_ROLE );
161
162   QString entries, entry;
163   const HEXA_NS::Shapes& assocs = hexaQuad->getAssociations();
164   for( HEXA_NS::Shapes::const_iterator anAssoc = assocs.begin(); anAssoc != assocs.end(); ++anAssoc ){
165     entry = (*anAssoc)->ident.c_str();
166     entries += entry + ";";
167   }
168   if ( !entries.isEmpty() )
169     setData( entries, HEXA_ASSOC_ENTRY_ROLE );
170 }
171
172
173 int QuadItem::type() const
174 {
175   return QUADITEM;
176 }
177
178 QVariant QuadItem::data( int role ) const
179 {
180         if ( role == HEXA_DATA_ROLE ){
181                 return QVariant::fromValue( _hexaQuad );
182         } else if ( role == Qt::ForegroundRole ) {
183                 const HEXA_NS::Shapes& assocs = _hexaQuad->getAssociations();
184                 if ( assocs.size()>0 )
185                         return QColor(Qt::darkGreen);
186                 else
187                         return QColor(Qt::black);
188         } else {
189                 return QStandardItem::data( role );
190         }
191 }
192
193 void QuadItem::setData ( const QVariant & value, int role )
194 {
195     if ( role == HEXA_DATA_ROLE ){
196       _hexaQuad = value.value<HEXA_NS::Quad*>();
197       emitDataChanged ();
198     } else {
199       QStandardItem::setData ( value, role );
200     }
201 }
202
203
204
205
206
207 // ----------------------- HEXA
208
209 HexaItem::HexaItem( HEXA_NS::Hexa* hexaHexa ):
210   QStandardItem(),
211   _hexaHexa( hexaHexa )
212 {
213 //   char pName[12];
214   QString name = _hexaHexa->getName(/*pName*/);
215   setText(name);
216   setData( HEXA_TREE, HEXA_TREE_ROLE );
217   setData( QString::number( reinterpret_cast<intptr_t>(_hexaHexa)), HEXA_ENTRY_ROLE );
218 }
219
220
221 int HexaItem::type() const
222 {
223   return HEXAITEM;
224 }
225
226 QVariant HexaItem::data( int role ) const
227 {
228         if ( role == HEXA_DATA_ROLE ){
229                 return QVariant::fromValue( _hexaHexa );
230         }
231         else if ( role == Qt::ForegroundRole ) {
232                 return QColor(Qt::black);
233         }
234         else {
235                 return QStandardItem::data( role );
236         }
237 }
238
239 void HexaItem::setData ( const QVariant & value, int role )
240 {
241     if ( role == HEXA_DATA_ROLE ){
242       _hexaHexa = value.value<HEXA_NS::Hexa*>();
243       emitDataChanged ();
244     } else {
245       QStandardItem::setData ( value, role );
246     }
247 }
248
249
250
251
252
253 // ----------------------- VECTOR
254 VectorItem::VectorItem( HEXA_NS::Vector* hexaVector ):
255   QStandardItem(),
256   _hexaVector( hexaVector )
257 {
258 //   char pName[12];
259   QString name = _hexaVector->getName(/*pName*/);
260   setText(name);
261   setData( VECTOR_TREE, HEXA_TREE_ROLE );
262   setData( QString::number(reinterpret_cast<intptr_t>(_hexaVector)), HEXA_ENTRY_ROLE );
263 }
264
265 int VectorItem::type() const
266 {
267   return VECTORITEM;
268 }
269
270 QVariant VectorItem::data( int role ) const 
271
272     if ( role == HEXA_DATA_ROLE ){
273       return QVariant::fromValue( _hexaVector );
274     } else {
275       return QStandardItem::data( role );
276     }
277 }
278
279 void VectorItem::setData ( const QVariant & value, int role )
280 {
281     if ( role == HEXA_DATA_ROLE ){
282       _hexaVector = value.value<HEXA_NS::Vector*>();
283       emitDataChanged ();
284     } else {
285       QStandardItem::setData ( value, role );
286     }
287 }
288
289
290
291
292 // ----------------------- CYLINDER
293 CylinderItem::CylinderItem( HEXA_NS::Cylinder* hexaCylinder):
294   QStandardItem(),
295   _hexaCylinder( hexaCylinder )
296 {
297 //   char pName[12];
298   QString name = _hexaCylinder->getName(/*pName*/);
299   setText(name);
300   setData( CYLINDER_TREE, HEXA_TREE_ROLE );
301   setData( QString::number(reinterpret_cast<intptr_t>(_hexaCylinder)), HEXA_ENTRY_ROLE );
302 }
303
304 int CylinderItem::type() const
305 {
306   return CYLINDERITEM;
307 }
308
309 QVariant CylinderItem::data( int role ) const 
310
311     if ( role == HEXA_DATA_ROLE ){
312       return QVariant::fromValue( _hexaCylinder );
313     } else {
314       return QStandardItem::data( role );
315     }
316 }
317
318 void CylinderItem::setData ( const QVariant & value, int role )
319 {
320     if ( role == HEXA_DATA_ROLE ){
321       _hexaCylinder = value.value<HEXA_NS::Cylinder*>();
322       emitDataChanged ();
323     } else {
324       QStandardItem::setData ( value, role );
325     }
326 }
327
328
329
330
331 // ----------------------- PIPE
332 PipeItem::PipeItem( HEXA_NS::Pipe* hexaPipe ):
333   QStandardItem(),
334   _hexaPipe( hexaPipe )
335 {
336 //   char pName[12];
337   QString name = _hexaPipe->getName(/*pName*/);
338   setText(name);
339   setData( PIPE_TREE, HEXA_TREE_ROLE );
340   setData( QString::number(reinterpret_cast<intptr_t>(_hexaPipe)), HEXA_ENTRY_ROLE );
341 }
342
343 int PipeItem::type() const
344 {
345   return PIPEITEM;
346 }
347
348 QVariant PipeItem::data( int role ) const 
349
350     if ( role == HEXA_DATA_ROLE ){
351       return QVariant::fromValue( _hexaPipe );
352     } else {
353       return QStandardItem::data( role );
354     }
355 }
356
357 void PipeItem::setData ( const QVariant & value, int role )
358 {
359     if ( role == HEXA_DATA_ROLE ){
360       _hexaPipe = value.value<HEXA_NS::Pipe*>();
361       emitDataChanged ();
362     } else {
363       QStandardItem::setData ( value, role );
364     }
365 }
366
367
368
369 // ----------------------- ELEMENTS
370 ElementsItem::ElementsItem( HEXA_NS::Elements* hexaElements ):
371   QStandardItem(),
372   _hexaElements( hexaElements )
373 {
374 //   char pName[12];
375   QString name = _hexaElements->getName(/*pName*/);
376   setText(name);
377   setData( ELEMENTS_TREE, HEXA_TREE_ROLE );
378   setData( QString::number(reinterpret_cast<intptr_t>(_hexaElements)), HEXA_ENTRY_ROLE );
379 }
380
381 int ElementsItem::type() const
382 {
383   return ELEMENTSITEM;
384 }
385
386 QVariant ElementsItem::data( int role ) const 
387
388     if ( role == HEXA_DATA_ROLE ){
389       return QVariant::fromValue( _hexaElements );
390     } else {
391       return QStandardItem::data( role );
392     }
393 }
394
395 void ElementsItem::setData ( const QVariant & value, int role )
396 {
397     if ( role == HEXA_DATA_ROLE ){
398       _hexaElements = value.value<HEXA_NS::Elements*>();
399       emitDataChanged ();
400     } else {
401       QStandardItem::setData ( value, role );
402     }
403 }
404
405
406
407 // ----------------------- CROSSELEMENTS
408 CrossElementsItem::CrossElementsItem( HEXA_NS::CrossElements* hexaCrossElts ):
409   QStandardItem(),
410   _hexaCrossElts( hexaCrossElts )
411 {
412 //   char pName[12];
413   QString name = _hexaCrossElts->getName(/*pName*/);
414   setText(name);
415   setData( CROSSELEMENTS_TREE, HEXA_TREE_ROLE );
416   setData( QString::number(reinterpret_cast<intptr_t>(_hexaCrossElts)), HEXA_ENTRY_ROLE );
417 }
418
419 int CrossElementsItem::type() const
420 {
421   return CROSSELEMENTSITEM;
422 }
423
424 QVariant CrossElementsItem::data( int role ) const 
425
426     if ( role == HEXA_DATA_ROLE ){
427       return QVariant::fromValue( _hexaCrossElts );
428     } else {
429       return QStandardItem::data( role );
430     }
431 }
432
433 void CrossElementsItem::setData ( const QVariant & value, int role )
434 {
435     if ( role == HEXA_DATA_ROLE ){
436       _hexaCrossElts = value.value<HEXA_NS::CrossElements*>();
437       emitDataChanged ();
438     } else {
439       QStandardItem::setData ( value, role );
440     }
441 }
442
443
444
445 // ----------------------- GROUP
446 GroupItem::GroupItem( HEXA_NS::Group* hexaGroup ):
447   QStandardItem(),
448   _hexaGroup( hexaGroup )
449 {
450 //   char pName[12];
451   QString name = _hexaGroup->getName();//pName);
452   setText(name);
453   setData( GROUP_TREE, HEXA_TREE_ROLE );
454   setData( QString::number(reinterpret_cast<intptr_t>(_hexaGroup)), HEXA_ENTRY_ROLE );
455 }
456
457 int GroupItem::type() const
458 {
459   return GROUPITEM;
460 }
461
462 QVariant GroupItem::data( int role ) const 
463
464     if ( role == HEXA_DATA_ROLE ){
465       return QVariant::fromValue( _hexaGroup );
466     } else {
467       return QStandardItem::data( role );
468     }
469 }
470
471 void GroupItem::setData ( const QVariant& value, int role )
472 {
473     if ( role == HEXA_DATA_ROLE ){
474       _hexaGroup = value.value<HEXA_NS::Group*>();
475       emitDataChanged ();
476     } else {
477       QStandardItem::setData ( value, role );
478     }
479 }
480
481
482
483 // ----------------------- LAW
484 LawItem::LawItem( HEXA_NS::Law* hexaLaw ):
485   QStandardItem(),
486   _hexaLaw( hexaLaw )
487 {
488 //   char pName[12];
489   QString name = _hexaLaw->getName();//pName);
490   setText(name);
491   setData( LAW_TREE, HEXA_TREE_ROLE );
492   setData( QString::number(reinterpret_cast<intptr_t>(_hexaLaw)), HEXA_ENTRY_ROLE );
493 }
494
495 int LawItem::type() const
496 {
497   return LAWITEM;
498 }
499
500 QVariant LawItem::data( int role ) const 
501
502     if ( role == HEXA_DATA_ROLE ){
503       return QVariant::fromValue( _hexaLaw);
504     } else {
505       return QStandardItem::data( role );
506     }
507 }
508
509 void LawItem::setData ( const QVariant & value, int role )
510 {
511     if ( role == HEXA_DATA_ROLE ){
512       _hexaLaw = value.value<HEXA_NS::Law*>();
513       emitDataChanged ();
514     } else {
515       QStandardItem::setData ( value, role );
516     }
517 }
518
519
520
521 // ----------------------- PROPAGATIONITEM
522 PropagationItem::PropagationItem( HEXA_NS::Propagation* hexaPropagation ):
523   QStandardItem(),
524   _hexaPropagation( hexaPropagation )
525 {
526 //   char pName[12];
527 //   QString name = _hexaPropagation->getName(pName);
528   QString name = "Propagation";
529   setText(name);
530   setData( PROPAGATION_TREE, HEXA_TREE_ROLE );
531   setData( QString::number(reinterpret_cast<intptr_t>(_hexaPropagation)), HEXA_ENTRY_ROLE );
532 }
533
534 int PropagationItem::type() const
535 {
536   return PROPAGATIONITEM;
537 }
538
539 QVariant PropagationItem::data( int role ) const 
540
541     if ( role == HEXA_DATA_ROLE ){
542       return QVariant::fromValue( _hexaPropagation );
543     } else {
544       return QStandardItem::data( role );
545     }
546 }
547
548 void PropagationItem::setData ( const QVariant & value, int role )
549 {
550     if ( role == HEXA_DATA_ROLE ){
551       _hexaPropagation = value.value<HEXA_NS::Propagation*>();
552       emitDataChanged ();
553     } else {
554       QStandardItem::setData ( value, role );
555     }
556 }