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
21 #include "HEXABLOCKGUI_DocumentItem.hxx"
22 #include "HexShape.hxx"
34 using namespace HEXABLOCK::GUI;
37 // ----------------------- VERTEX
39 VertexItem::VertexItem( HEXA_NS::Vertex* hexaVertex ):
41 _hexaVertex( hexaVertex )
44 QString name = _hexaVertex->getName(/*pName*/);
45 // QString docEntry = model()->invisibleRootItem()->data(HEXA_ENTRY_ROLE).toString();
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()
51 HEXA_NS::Shape* assoc = hexaVertex->getAssociation();
53 QString entry = QString(assoc->ident.c_str());
54 setData( entry + ";" , HEXA_ASSOC_ENTRY_ROLE );
58 int VertexItem::type() const
65 QVariant VertexItem::data( int role ) const
67 if ( role == HEXA_DATA_ROLE ){
68 return QVariant::fromValue( _hexaVertex );
69 } else if (role == Qt::ForegroundRole ) {
70 HEXA_NS::Shape* assoc = _hexaVertex->getAssociation();
72 return QColor(Qt::darkGreen);
74 return QColor(Qt::black);
76 return QStandardItem::data( role );
80 void VertexItem::setData ( const QVariant & value, int role )
82 if ( role == HEXA_DATA_ROLE ){
83 _hexaVertex = value.value<HEXA_NS::Vertex*>();
86 // std::cout << " VertexItem::setData( " << role << ", "<< value.toString().toStdString() << " )" <<std::endl;
87 QStandardItem::setData ( value, role );
93 // ----------------------- EDGE
94 EdgeItem::EdgeItem( HEXA_NS::Edge* hexaEdge ):
99 // QString name = _hexaEdge->getName(pName);
100 QString name = _hexaEdge->getName();
101 // std::cout << "EdgeItem name : "<< name.toStdString() << std::endl;
103 setData( EDGE_TREE, HEXA_TREE_ROLE );
104 setData( QString::number( reinterpret_cast<intptr_t>(_hexaEdge) ), HEXA_ENTRY_ROLE );
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 + ";";
112 if ( !entries.isEmpty() )
113 setData( entries, HEXA_ASSOC_ENTRY_ROLE );
118 int EdgeItem::type() const
123 QVariant EdgeItem::data( int role ) const
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);
132 return QColor(Qt::black);
134 return QStandardItem::data( role );
138 void EdgeItem::setData ( const QVariant & value, int role )
140 if ( role == HEXA_DATA_ROLE ){
141 _hexaEdge = value.value<HEXA_NS::Edge*>();
144 QStandardItem::setData ( value, role );
151 // ----------------------- QUAD
152 QuadItem::QuadItem( HEXA_NS::Quad* hexaQuad ):
154 _hexaQuad( hexaQuad )
157 QString name = _hexaQuad->getName(/*pName*/);
159 setData( QUAD_TREE, HEXA_TREE_ROLE );
160 setData( QString::number(reinterpret_cast<intptr_t>(_hexaQuad)), HEXA_ENTRY_ROLE );
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 + ";";
168 if ( !entries.isEmpty() )
169 setData( entries, HEXA_ASSOC_ENTRY_ROLE );
173 int QuadItem::type() const
178 QVariant QuadItem::data( int role ) const
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);
187 return QColor(Qt::black);
189 return QStandardItem::data( role );
193 void QuadItem::setData ( const QVariant & value, int role )
195 if ( role == HEXA_DATA_ROLE ){
196 _hexaQuad = value.value<HEXA_NS::Quad*>();
199 QStandardItem::setData ( value, role );
207 // ----------------------- HEXA
209 HexaItem::HexaItem( HEXA_NS::Hexa* hexaHexa ):
211 _hexaHexa( hexaHexa )
214 QString name = _hexaHexa->getName(/*pName*/);
216 setData( HEXA_TREE, HEXA_TREE_ROLE );
217 setData( QString::number( reinterpret_cast<intptr_t>(_hexaHexa)), HEXA_ENTRY_ROLE );
221 int HexaItem::type() const
226 QVariant HexaItem::data( int role ) const
228 if ( role == HEXA_DATA_ROLE ){
229 return QVariant::fromValue( _hexaHexa );
231 else if ( role == Qt::ForegroundRole ) {
232 return QColor(Qt::black);
235 return QStandardItem::data( role );
239 void HexaItem::setData ( const QVariant & value, int role )
241 if ( role == HEXA_DATA_ROLE ){
242 _hexaHexa = value.value<HEXA_NS::Hexa*>();
245 QStandardItem::setData ( value, role );
253 // ----------------------- VECTOR
254 VectorItem::VectorItem( HEXA_NS::Vector* hexaVector ):
256 _hexaVector( hexaVector )
259 QString name = _hexaVector->getName(/*pName*/);
261 setData( VECTOR_TREE, HEXA_TREE_ROLE );
262 setData( QString::number(reinterpret_cast<intptr_t>(_hexaVector)), HEXA_ENTRY_ROLE );
265 int VectorItem::type() const
270 QVariant VectorItem::data( int role ) const
272 if ( role == HEXA_DATA_ROLE ){
273 return QVariant::fromValue( _hexaVector );
275 return QStandardItem::data( role );
279 void VectorItem::setData ( const QVariant & value, int role )
281 if ( role == HEXA_DATA_ROLE ){
282 _hexaVector = value.value<HEXA_NS::Vector*>();
285 QStandardItem::setData ( value, role );
292 // ----------------------- CYLINDER
293 CylinderItem::CylinderItem( HEXA_NS::Cylinder* hexaCylinder):
295 _hexaCylinder( hexaCylinder )
298 QString name = _hexaCylinder->getName(/*pName*/);
300 setData( CYLINDER_TREE, HEXA_TREE_ROLE );
301 setData( QString::number(reinterpret_cast<intptr_t>(_hexaCylinder)), HEXA_ENTRY_ROLE );
304 int CylinderItem::type() const
309 QVariant CylinderItem::data( int role ) const
311 if ( role == HEXA_DATA_ROLE ){
312 return QVariant::fromValue( _hexaCylinder );
314 return QStandardItem::data( role );
318 void CylinderItem::setData ( const QVariant & value, int role )
320 if ( role == HEXA_DATA_ROLE ){
321 _hexaCylinder = value.value<HEXA_NS::Cylinder*>();
324 QStandardItem::setData ( value, role );
331 // ----------------------- PIPE
332 PipeItem::PipeItem( HEXA_NS::Pipe* hexaPipe ):
334 _hexaPipe( hexaPipe )
337 QString name = _hexaPipe->getName(/*pName*/);
339 setData( PIPE_TREE, HEXA_TREE_ROLE );
340 setData( QString::number(reinterpret_cast<intptr_t>(_hexaPipe)), HEXA_ENTRY_ROLE );
343 int PipeItem::type() const
348 QVariant PipeItem::data( int role ) const
350 if ( role == HEXA_DATA_ROLE ){
351 return QVariant::fromValue( _hexaPipe );
353 return QStandardItem::data( role );
357 void PipeItem::setData ( const QVariant & value, int role )
359 if ( role == HEXA_DATA_ROLE ){
360 _hexaPipe = value.value<HEXA_NS::Pipe*>();
363 QStandardItem::setData ( value, role );
369 // ----------------------- ELEMENTS
370 ElementsItem::ElementsItem( HEXA_NS::Elements* hexaElements ):
372 _hexaElements( hexaElements )
375 QString name = _hexaElements->getName(/*pName*/);
377 setData( ELEMENTS_TREE, HEXA_TREE_ROLE );
378 setData( QString::number(reinterpret_cast<intptr_t>(_hexaElements)), HEXA_ENTRY_ROLE );
381 int ElementsItem::type() const
386 QVariant ElementsItem::data( int role ) const
388 if ( role == HEXA_DATA_ROLE ){
389 return QVariant::fromValue( _hexaElements );
391 return QStandardItem::data( role );
395 void ElementsItem::setData ( const QVariant & value, int role )
397 if ( role == HEXA_DATA_ROLE ){
398 _hexaElements = value.value<HEXA_NS::Elements*>();
401 QStandardItem::setData ( value, role );
407 // ----------------------- CROSSELEMENTS
408 CrossElementsItem::CrossElementsItem( HEXA_NS::CrossElements* hexaCrossElts ):
410 _hexaCrossElts( hexaCrossElts )
413 QString name = _hexaCrossElts->getName(/*pName*/);
415 setData( CROSSELEMENTS_TREE, HEXA_TREE_ROLE );
416 setData( QString::number(reinterpret_cast<intptr_t>(_hexaCrossElts)), HEXA_ENTRY_ROLE );
419 int CrossElementsItem::type() const
421 return CROSSELEMENTSITEM;
424 QVariant CrossElementsItem::data( int role ) const
426 if ( role == HEXA_DATA_ROLE ){
427 return QVariant::fromValue( _hexaCrossElts );
429 return QStandardItem::data( role );
433 void CrossElementsItem::setData ( const QVariant & value, int role )
435 if ( role == HEXA_DATA_ROLE ){
436 _hexaCrossElts = value.value<HEXA_NS::CrossElements*>();
439 QStandardItem::setData ( value, role );
445 // ----------------------- GROUP
446 GroupItem::GroupItem( HEXA_NS::Group* hexaGroup ):
448 _hexaGroup( hexaGroup )
451 QString name = _hexaGroup->getName();//pName);
453 setData( GROUP_TREE, HEXA_TREE_ROLE );
454 setData( QString::number(reinterpret_cast<intptr_t>(_hexaGroup)), HEXA_ENTRY_ROLE );
457 int GroupItem::type() const
462 QVariant GroupItem::data( int role ) const
464 if ( role == HEXA_DATA_ROLE ){
465 return QVariant::fromValue( _hexaGroup );
467 return QStandardItem::data( role );
471 void GroupItem::setData ( const QVariant& value, int role )
473 if ( role == HEXA_DATA_ROLE ){
474 _hexaGroup = value.value<HEXA_NS::Group*>();
477 QStandardItem::setData ( value, role );
483 // ----------------------- LAW
484 LawItem::LawItem( HEXA_NS::Law* hexaLaw ):
489 QString name = _hexaLaw->getName();//pName);
491 setData( LAW_TREE, HEXA_TREE_ROLE );
492 setData( QString::number(reinterpret_cast<intptr_t>(_hexaLaw)), HEXA_ENTRY_ROLE );
495 int LawItem::type() const
500 QVariant LawItem::data( int role ) const
502 if ( role == HEXA_DATA_ROLE ){
503 return QVariant::fromValue( _hexaLaw);
505 return QStandardItem::data( role );
509 void LawItem::setData ( const QVariant & value, int role )
511 if ( role == HEXA_DATA_ROLE ){
512 _hexaLaw = value.value<HEXA_NS::Law*>();
515 QStandardItem::setData ( value, role );
521 // ----------------------- PROPAGATIONITEM
522 PropagationItem::PropagationItem( HEXA_NS::Propagation* hexaPropagation ):
524 _hexaPropagation( hexaPropagation )
527 // QString name = _hexaPropagation->getName(pName);
528 QString name = "Propagation";
530 setData( PROPAGATION_TREE, HEXA_TREE_ROLE );
531 setData( QString::number(reinterpret_cast<intptr_t>(_hexaPropagation)), HEXA_ENTRY_ROLE );
534 int PropagationItem::type() const
536 return PROPAGATIONITEM;
539 QVariant PropagationItem::data( int role ) const
541 if ( role == HEXA_DATA_ROLE ){
542 return QVariant::fromValue( _hexaPropagation );
544 return QStandardItem::data( role );
548 void PropagationItem::setData ( const QVariant & value, int role )
550 if ( role == HEXA_DATA_ROLE ){
551 _hexaPropagation = value.value<HEXA_NS::Propagation*>();
554 QStandardItem::setData ( value, role );