]> SALOME platform Git repositories - modules/gui.git/blob - src/LightApp/LightApp_DataObject.cxx
Salome HOME
PAL10670 - it is necessary to increase speed of selection and popup construction...
[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/
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 /*
77         Class: LightApp_DataObject
78         Level: Public
79 */
80 /*!Constructor. Initialize by \a parent*/
81 LightApp_DataObject::LightApp_DataObject( SUIT_DataObject* parent )
82 : CAM_DataObject( parent ), myCompObject( 0 ), myCompDataType( "" )
83 {
84 }
85
86 /*!Destructor. Do nothing.*/
87 LightApp_DataObject::~LightApp_DataObject()
88 {
89 }
90
91 /*!Gets object ID.
92  *\retval QString
93  */
94 QString LightApp_DataObject::entry() const
95 {
96   return QString::null;
97 }
98
99 /*!Create and return new key object.*/
100 SUIT_DataObjectKey* LightApp_DataObject::key() const
101 {
102   QString str = entry();
103   return new Key( str );
104 }
105
106 /*!Gets component object.
107  *\retval SUIT_DataObject.
108  */
109 SUIT_DataObject* LightApp_DataObject::componentObject() const
110 {
111   if ( !myCompObject ) {
112   SUIT_DataObject* compObj = 0; // for root object
113
114     if ( parent() && parent() == root() ) 
115       compObj = (SUIT_DataObject*)this; // for component-level objects
116     else 
117     {
118       compObj = parent(); // for lower level objects
119       while ( compObj && compObj->parent() != root() )
120         compObj = compObj->parent();
121     }
122     LightApp_DataObject* that = (LightApp_DataObject*)this;
123     that->myCompObject = compObj;
124   }
125   return myCompObject;
126 }
127
128 /*!Get component type.*/
129 QString LightApp_DataObject::componentDataType() const
130 {
131   if ( myCompDataType.isEmpty() ) {
132   SUIT_DataObject* aCompObj = componentObject();
133     LightApp_ModuleObject* anObj = dynamic_cast<LightApp_ModuleObject*>( aCompObj );
134     if ( anObj ) {
135       CAM_DataModel* aModel = anObj->dataModel();
136       if ( aModel ) {
137         LightApp_DataObject* that = (LightApp_DataObject*)this;
138         that->myCompDataType = aModel->module()->name();
139       }
140     }
141   }
142   return myCompDataType;
143 }
144
145 /*
146         Class: LightApp_ModuleObject
147         Level: Public
148 */
149
150 /*!Constructor.Initialize by \a parent.*/
151 LightApp_ModuleObject::LightApp_ModuleObject( SUIT_DataObject* parent )
152 : CAM_RootObject( parent ),
153   CAM_DataObject( parent )
154 {
155 }
156
157 /*!Constructor.Initialize by \a module and parent.*/
158 LightApp_ModuleObject::LightApp_ModuleObject( CAM_DataModel* dm, SUIT_DataObject* parent )
159 : CAM_RootObject( dm, parent ),
160   CAM_DataObject( parent )
161 {
162 }
163
164 /*!Destructor. Do nothing.*/
165 LightApp_ModuleObject::~LightApp_ModuleObject()
166 {
167 }
168
169 /*!Returns module name */
170 QString LightApp_ModuleObject::name() const
171 {
172   return CAM_RootObject::name();
173 }
174
175 /*!Insert new child object to the children list at specified position
176  *\add component in Study for this module object if it necessary*/
177 void LightApp_ModuleObject::insertChild( SUIT_DataObject* theObj, int thePosition )
178 {
179   CAM_RootObject::insertChild(theObj, thePosition);
180
181   CAM_DataModel* aModel = dataModel();
182
183   LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>(parent());
184
185   if (aRoot)
186     aRoot->study()->addComponent(aModel);
187
188
189 }