1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA 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/
19 #include "LightApp_DataObject.h"
21 #include "LightApp_Study.h"
22 #include "LightApp_RootObject.h"
24 #include "CAM_DataModel.h"
25 #include "CAM_Module.h"
27 #include <SUIT_Application.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SUIT_DataObjectKey.h>
34 Class: LightApp_DataObject::Key
37 class LightApp_DataObject::Key : public SUIT_DataObjectKey
40 Key( const QString& );
43 virtual bool isLess( const SUIT_DataObjectKey* ) const;
44 virtual bool isEqual( const SUIT_DataObjectKey* ) const;
50 /*!Constructor. Initialize by \a entry.*/
51 LightApp_DataObject::Key::Key( const QString& entry )
52 : SUIT_DataObjectKey(),
57 /*!Destructor. Do nothing.*/
58 LightApp_DataObject::Key::~Key()
62 /*!Checks: Is current key less than \a other.*/
63 bool LightApp_DataObject::Key::isLess( const SUIT_DataObjectKey* other ) const
65 Key* that = (Key*)other;
66 return myEntry < that->myEntry;
69 /*!Checks: Is current key equal with \a other.*/
70 bool LightApp_DataObject::Key::isEqual( const SUIT_DataObjectKey* other ) const
72 Key* that = (Key*)other;
73 return myEntry == that->myEntry;
77 Class: LightApp_DataObject
80 /*!Constructor. Initialize by \a parent*/
81 LightApp_DataObject::LightApp_DataObject( SUIT_DataObject* parent )
82 : CAM_DataObject( parent ), myCompObject( 0 ), myCompDataType( "" )
86 /*!Destructor. Do nothing.*/
87 LightApp_DataObject::~LightApp_DataObject()
94 QString LightApp_DataObject::entry() const
99 /*!Create and return new key object.*/
100 SUIT_DataObjectKey* LightApp_DataObject::key() const
102 QString str = entry();
103 return new Key( str );
106 /*!Gets component object.
107 *\retval SUIT_DataObject.
109 SUIT_DataObject* LightApp_DataObject::componentObject() const
111 if ( !myCompObject ) {
112 SUIT_DataObject* compObj = 0; // for root object
114 if ( parent() && parent() == root() )
115 compObj = (SUIT_DataObject*)this; // for component-level objects
118 compObj = parent(); // for lower level objects
119 while ( compObj && compObj->parent() != root() )
120 compObj = compObj->parent();
122 LightApp_DataObject* that = (LightApp_DataObject*)this;
123 that->myCompObject = compObj;
128 /*!Get component type.*/
129 QString LightApp_DataObject::componentDataType() const
131 if ( myCompDataType.isEmpty() ) {
132 SUIT_DataObject* aCompObj = componentObject();
133 LightApp_ModuleObject* anObj = dynamic_cast<LightApp_ModuleObject*>( aCompObj );
135 CAM_DataModel* aModel = anObj->dataModel();
137 LightApp_DataObject* that = (LightApp_DataObject*)this;
138 that->myCompDataType = aModel->module()->name();
142 return myCompDataType;
146 Class: LightApp_ModuleObject
150 /*!Constructor.Initialize by \a parent.*/
151 LightApp_ModuleObject::LightApp_ModuleObject( SUIT_DataObject* parent )
152 : CAM_RootObject( parent ),
153 CAM_DataObject( parent )
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 )
164 /*!Destructor. Do nothing.*/
165 LightApp_ModuleObject::~LightApp_ModuleObject()
169 /*!Returns module name */
170 QString LightApp_ModuleObject::name() const
172 return CAM_RootObject::name();
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 )
179 CAM_RootObject::insertChild(theObj, thePosition);
181 CAM_DataModel* aModel = dataModel();
183 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>(parent());
186 aRoot->study()->addComponent(aModel);