]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROGUI/HYDROGUI_DataObject.cxx
Salome HOME
1) Data model draft.
[modules/hydro.git] / src / HYDROGUI / HYDROGUI_DataObject.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "HYDROGUI_DataObject.h"
24
25 #include <SUIT_DataObject.h>
26
27 HYDROGUI_DataObject::HYDROGUI_DataObject( SUIT_DataObject* theParent, 
28                                           Handle(HYDROData_Object) theData )
29 : CAM_DataObject( theParent ),
30   LightApp_DataObject( theParent ),
31   myData( theData )
32 {
33   // unique identifier generated from pointer to this object, like: "HD_0x123457"
34   // "H" means "HYDRO", "D" means "data" to avoid conflicts with named objects
35   std::ostringstream aStream; 
36   aStream << "HD_" << this;
37   myEntry = QString( aStream.str().c_str() );
38 }
39
40 QString HYDROGUI_DataObject::entry() const
41 {
42   return myEntry;
43 }
44
45 QString HYDROGUI_DataObject::name() const
46 {
47   if( !myData.IsNull() )
48     return myData->GetName();
49   return QString();
50 }
51
52 HYDROGUI_DataObject* HYDROGUI_DataObject::objectByEntry( const QString& theEntry )
53 {
54   static const QString aPrefixD( "HD_" );
55   if ( theEntry.indexOf( aPrefixD ) != 0 ) 
56     return NULL; // not HYDRO entry
57   
58   std::istringstream aStream( theEntry.toLatin1().constData() + 3 ); // start reading just after "HD_"
59   void* aPtr = 0;
60   aStream >> aPtr;
61
62   return ( HYDROGUI_DataObject* )aPtr;
63 }
64
65 HYDROGUI_NamedObject::HYDROGUI_NamedObject( SUIT_DataObject* theParent,
66                                             const QString& theName )
67 : CAM_DataObject( theParent ),
68   LightApp_DataObject( theParent ),
69   myName( theName )
70 {
71 }
72
73 QString HYDROGUI_NamedObject::entry() const
74 {
75   // unique identifier generated from pointer to this object, like: "HD_0x123457"
76   // "H" means "HYDRO", "N" means "named" to avoid conflicts with data objects
77   return "HN_" + myName;
78 }
79
80 QString HYDROGUI_NamedObject::name() const
81 {
82   return myName;
83 }
84
85 QString HYDROGUI_NamedObject::nameByEntry( const QString& theEntry )
86 {
87   static const QString aPrefixN( "HN_" );
88   if( theEntry.indexOf( aPrefixN ) != 0 ) 
89     return QString(); // not HYDRO entry
90   
91   return theEntry.right( 3 );
92 }