Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/gui.git] / src / LightApp / LightApp_DataObject.cxx
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA 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 #include "LightApp_DataObject.h"
20
21 #include "LightApp_Study.h"
22 #include "LightApp_RootObject.h"
23
24 #include "CAM_DataModel.h"
25 #include "CAM_Module.h"
26
27 #include <SUIT_Application.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_DataObjectKey.h>
30
31 #include <qobject.h>
32
33 /*!
34         Class: LightApp_DataObject::Key
35         Level: Internal
36 */
37 class LightApp_DataObject::Key : public SUIT_DataObjectKey
38 {
39 public:
40   Key( const QString& );
41   virtual ~Key();
42
43   virtual bool isLess( const SUIT_DataObjectKey* ) const;
44   virtual bool isEqual( const SUIT_DataObjectKey* ) const;
45
46 private:
47   QString myEntry;
48 };
49
50 /*!Constructor. Initialize by \a entry.*/
51 LightApp_DataObject::Key::Key( const QString& entry )
52 : SUIT_DataObjectKey(),
53   myEntry( entry )
54 {
55 }
56
57 /*!Destructor. Do nothing.*/
58 LightApp_DataObject::Key::~Key()
59 {
60 }
61
62 /*!Checks: Is current key less than \a other.*/
63 bool LightApp_DataObject::Key::isLess( const SUIT_DataObjectKey* other ) const
64 {
65   Key* that = (Key*)other;
66   return myEntry < that->myEntry;
67 }
68
69 /*!Checks: Is current key equal with \a other.*/
70 bool LightApp_DataObject::Key::isEqual( const SUIT_DataObjectKey* other ) const
71 {
72   Key* that = (Key*)other;
73   return myEntry == that->myEntry;
74 }
75
76 /*!Constructor. Initialize by \a parent*/
77 LightApp_DataObject::LightApp_DataObject( SUIT_DataObject* parent )
78 : CAM_DataObject( parent ), myCompObject( 0 ), myCompDataType( "" )
79 {
80 }
81
82 /*!Destructor. Do nothing.*/
83 LightApp_DataObject::~LightApp_DataObject()
84 {
85 }
86
87 /*!Gets object ID.
88  *\retval QString
89  */
90 QString LightApp_DataObject::entry() const
91 {
92   return QString::null;
93 }
94
95 /*!Create and return new key object.*/
96 SUIT_DataObjectKey* LightApp_DataObject::key() const
97 {
98   QString str = entry();
99   return new Key( str );
100 }
101
102 /*!Gets component object.
103  *\retval SUIT_DataObject.
104  */
105 SUIT_DataObject* LightApp_DataObject::componentObject() const
106 {
107   if ( !myCompObject ) {
108   SUIT_DataObject* compObj = 0; // for root object
109
110     if ( parent() && parent() == root() ) 
111       compObj = (SUIT_DataObject*)this; // for component-level objects
112     else 
113     {
114       compObj = parent(); // for lower level objects
115       while ( compObj && compObj->parent() != root() )
116         compObj = compObj->parent();
117     }
118     LightApp_DataObject* that = (LightApp_DataObject*)this;
119     that->myCompObject = compObj;
120   }
121   return myCompObject;
122 }
123
124 /*!Get component type.*/
125 QString LightApp_DataObject::componentDataType() const
126 {
127   if ( myCompDataType.isEmpty() ) {
128   SUIT_DataObject* aCompObj = componentObject();
129     LightApp_ModuleObject* anObj = dynamic_cast<LightApp_ModuleObject*>( aCompObj );
130     if ( anObj ) {
131       CAM_DataModel* aModel = anObj->dataModel();
132       if ( aModel ) {
133         LightApp_DataObject* that = (LightApp_DataObject*)this;
134         that->myCompDataType = aModel->module()->name();
135       }
136     }
137   }
138   return myCompDataType;
139 }
140
141
142
143 /*!Constructor.Initialize by \a parent.*/
144 LightApp_ModuleObject::LightApp_ModuleObject( SUIT_DataObject* parent )
145 : CAM_RootObject( parent ),
146   CAM_DataObject( parent )
147 {
148 }
149
150 /*!Constructor.Initialize by \a module and parent.*/
151 LightApp_ModuleObject::LightApp_ModuleObject( CAM_DataModel* dm, SUIT_DataObject* parent )
152 : CAM_RootObject( dm, parent ),
153   CAM_DataObject( parent )
154 {
155 }
156
157 /*!Destructor. Do nothing.*/
158 LightApp_ModuleObject::~LightApp_ModuleObject()
159 {
160 }
161
162 /*!Returns module name */
163 QString LightApp_ModuleObject::name() const
164 {
165   return CAM_RootObject::name();
166 }
167
168 /*!Insert new child object to the children list at specified position
169  *\add component in Study for this module object if it necessary*/
170 void LightApp_ModuleObject::insertChild( SUIT_DataObject* theObj, int thePosition )
171 {
172   CAM_RootObject::insertChild(theObj, thePosition);
173
174   CAM_DataModel* aModel = dataModel();
175
176   LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>(parent());
177
178   if (aRoot)
179     aRoot->study()->addComponent(aModel);
180
181
182 }