]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_DataObject.cxx
Salome HOME
refs #1323, icons of imm. zones (only) are changing while switching between sumb...
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataObject.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include "HYDROGUI_DataObject.h"
20
21 #include <HYDROData_DummyObject3D.h>
22 #include <HYDROData_ImmersibleZone.h>
23 #include <HYDROData_Object.h>
24
25 #include <TDF_Tool.hxx>
26
27 #include <SUIT_DataObject.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_Session.h>
30 #include <SUIT_Operation.h>
31 #include <CAM_Module.h>
32 #include <CAM_Application.h>
33 #include <SUIT_Study.h>
34
35 #include <QPixmap>
36
37 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, 
38                                           Handle(HYDROData_Entity) theData,
39                                           const QString& theParentEntry,
40                                           const bool theIsInOperation )
41 : CAM_DataObject( theParent ),
42   LightApp_DataObject( theParent ),
43   myData( theData ),
44   myParentEntry( theParentEntry ),
45   myIsValid( true ),
46   myIsInOperation( theIsInOperation )
47 {
48 }
49
50 QString HYDROGUI_DataObject::entry() const
51 {
52   QString anEntry = HYDROGUI_DataObject::dataObjectEntry( modelObject() );
53   if( isReference() )
54     anEntry.prepend( myParentEntry + "_" );
55   return anEntry;
56 }
57
58 QString HYDROGUI_DataObject::refEntry() const
59 {
60   if( !myParentEntry.isEmpty() )
61     return HYDROGUI_DataObject::dataObjectEntry( modelObject() );
62   return QString();
63 }
64
65 QString HYDROGUI_DataObject::name() const
66 {
67   if( !myData.IsNull() )
68     return myData->GetName();
69   return QString();
70 }
71
72 QFont HYDROGUI_DataObject::font( const int theId ) const
73 {
74   QFont aFont = LightApp_DataObject::font( theId );
75   if( theId == NameId )
76   {
77     Handle(HYDROData_Entity) aDataObject = modelObject();
78     if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
79     {
80       aFont.setItalic( true );
81       aFont.setBold( true );
82     }
83   }
84   return aFont;
85 }
86
87 QColor HYDROGUI_DataObject::color( const ColorRole theRole, const int theId ) const
88 {
89   QColor aColor;
90
91   if ( !isValid() ) {
92     switch ( theRole )
93     {
94       case Text:
95       case Foreground:
96       case Highlight:
97         aColor = Qt::red; // red
98       break;
99       case HighlightedText:
100         // text color for the highlighted item
101         aColor = Qt::white;   // white
102       break;
103
104       default:
105         break;
106     }
107   }
108
109   if ( !aColor.isValid() )
110   {
111     Handle(HYDROData_Entity) aDataObject = modelObject();
112     if( !aDataObject.IsNull() && aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) )
113     {
114       switch ( theRole )
115       {
116         case Text:
117         case Foreground:
118         case Highlight:
119           aColor = Qt::blue;    // color for objects which need updating
120         break;
121         case HighlightedText:
122           // text color for the highlighted item
123           aColor = Qt::white;   // white
124         break;
125
126         default:
127           break;
128       }
129     }
130   }
131
132   if ( !aColor.isValid() ) {
133     aColor = LightApp_DataObject::color( theRole, theId );
134   }
135
136   return aColor;
137 }
138
139 QPixmap HYDROGUI_DataObject::icon( const int theId ) const
140 {
141   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
142   if ( theId == NameId )
143   {
144     QString anIcon;
145     Handle(HYDROData_Entity) aDataObject = modelObject();
146     if( aDataObject.IsNull() )
147     {
148       anIcon = QObject::tr( "HYDRO_TYPE0_ICO" ); // KIND_UNKNOWN
149     }
150     else
151     {
152       QString aNeedUpdate( aDataObject->IsMustBeUpdated( HYDROData_Entity::Geom_All ) ? "M_" : "" );
153
154       int anObjectKind = (int)aDataObject->GetKind();
155       bool IsUnsImmZone = false;
156       if ( anObjectKind == KIND_DUMMY_3D )
157       {
158         Handle(HYDROData_DummyObject3D) anObject3D = 
159           Handle(HYDROData_DummyObject3D)::DownCast( aDataObject );
160         
161         Handle(HYDROData_Object) aFatherObj = anObject3D->GetObject();
162         if ( !aFatherObj.IsNull() )
163           anObjectKind = aFatherObj->GetKind();
164       }
165       else if ( anObjectKind == 5 )
166       {
167         Handle(HYDROData_ImmersibleZone) anImmZone = Handle(HYDROData_ImmersibleZone)::DownCast( aDataObject );
168         IsUnsImmZone = !anImmZone->IsSubmersible();
169       }
170       if (!IsUnsImmZone)
171         anIcon = QObject::tr( QString("HYDRO_%1TYPE%2_ICO").arg( aNeedUpdate ).arg( anObjectKind ).toLatin1() );
172       else
173         anIcon = QObject::tr( QString("HYDRO_%1TYPE5U_ICO").arg( aNeedUpdate ).toLatin1() ); //icon fot unsumb imm zone
174     }
175
176     return aResMgr->loadPixmap( "HYDRO", anIcon );
177   }
178   return LightApp_DataObject::icon( theId );
179 }
180
181 QString HYDROGUI_DataObject::dataObjectEntry( const Handle(HYDROData_Entity)& theObject,
182                                               const bool theWithPrefix )
183 {
184   QString aEntryStr = QString::null;
185   if( !theObject.IsNull() )
186   {
187     TCollection_AsciiString aLabEntr;
188     TDF_Tool::Entry( theObject->Label(), aLabEntr );
189     aEntryStr = aLabEntr.ToCString();
190     if( theWithPrefix )
191       aEntryStr.prepend( HYDROGUI_DataObject::entryPrefix() );
192   }
193   return aEntryStr;
194 }
195
196 void HYDROGUI_DataObject::setIsValid( const bool theIsValid )
197 {
198   myIsValid = theIsValid;
199 }
200
201 bool HYDROGUI_DataObject::isValid() const
202 {
203   return myIsValid;
204 }
205
206 bool HYDROGUI_DataObject::renameAllowed( const int theColumnId ) const
207 {
208   bool aRes = false;
209   if ( theColumnId == NameId && module())
210   {
211     SUIT_Operation* anOp = module()->application()->activeStudy()->activeOperation();
212     if ( anOp && anOp->inherits( "HYDROGUI_CalculationOp" ) )
213     {
214       aRes = isInOperation();
215     }
216     else
217     {
218       aRes = !anOp;
219     }
220   }
221   else
222   {
223     aRes = LightApp_DataObject::renameAllowed( theColumnId );
224   }
225   return aRes;
226 }
227
228 void HYDROGUI_DataObject::updateBy( SUIT_DataObject* theObj )
229 {
230   HYDROGUI_DataObject* aDataObj = dynamic_cast<HYDROGUI_DataObject*>( theObj );
231   if( !aDataObj )
232     return;
233
234   myData = aDataObj->myData;
235   myParentEntry = aDataObj->myParentEntry;
236   myIsValid = aDataObj->myIsValid;
237   myIsInOperation = aDataObj->myIsInOperation;
238   myIcon = aDataObj->myIcon;
239   setModified( true );
240 }
241
242 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
243                                             const QString&   theName,
244                                             const QString&   theParentEntry,
245                                             const bool       theIsInOperation  )
246 : CAM_DataObject( theParent ),
247   LightApp_DataObject( theParent ),
248   myName( theName ),
249   myParentEntry( theParentEntry ),
250   myIsInOperation( theIsInOperation )
251 {
252 }
253
254 QString HYDROGUI_NamedObject::entry() const
255 {
256   QString anEntry = HYDROGUI_DataObject::entryPrefix() + name();
257   if( !myParentEntry.isEmpty() )
258     anEntry.prepend( myParentEntry + "_" );
259   return anEntry;
260 }
261
262 QString HYDROGUI_NamedObject::name() const
263 {
264   return myName.toUpper();
265 }
266
267 QPixmap HYDROGUI_NamedObject::icon( const int theId ) const
268 {
269   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
270   if ( theId == NameId )
271   {
272     return aResMgr->loadPixmap( "HYDRO", QObject::tr( "PARTITION_ICO" ) );
273   }
274   return LightApp_DataObject::icon( theId );
275 }
276
277 QFont HYDROGUI_NamedObject::font( const int theId ) const
278 {
279   QFont aFont = LightApp_DataObject::font( theId );
280   if( theId == NameId )
281   {
282   if ( dynamic_cast<CAM_ModuleObject*>( parent() ) )
283     {
284       aFont.setBold( true );
285     }
286   }
287   return aFont;
288 }
289
290 void HYDROGUI_NamedObject::updateBy( SUIT_DataObject* theObj )
291 {
292   HYDROGUI_NamedObject* aNamedObj = dynamic_cast<HYDROGUI_NamedObject*>( theObj );
293   if( !aNamedObj )
294     return;
295
296   myName = aNamedObj->myName;
297   myParentEntry = aNamedObj->myParentEntry;
298   myIcon = aNamedObj->myIcon;
299   myIsInOperation = aNamedObj->myIsInOperation;
300   setModified( true );
301 }
302
303
304
305
306
307
308 HYDROGUI_DropTargetObject::HYDROGUI_DropTargetObject( SUIT_DataObject* theParent,
309                                             const QString&   theName,
310                                             const QString&   theParentEntry,
311                                             const bool       theIsInOperation  )
312 : HYDROGUI_NamedObject( theParent, theName, theParentEntry, theIsInOperation ), 
313   CAM_DataObject( theParent )
314 {
315 }