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/ or email : webmaster.salome@opencascade.com
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;
76 /*!Constructor. Initialize by \a parent*/
77 LightApp_DataObject::LightApp_DataObject( SUIT_DataObject* parent )
78 : CAM_DataObject( parent ), myCompObject( 0 ), myCompDataType( "" )
82 /*!Destructor. Do nothing.*/
83 LightApp_DataObject::~LightApp_DataObject()
90 QString LightApp_DataObject::entry() const
95 /*!Create and return new key object.*/
96 SUIT_DataObjectKey* LightApp_DataObject::key() const
98 QString str = entry();
99 return new Key( str );
102 /*!Gets component object.
103 *\retval SUIT_DataObject.
105 SUIT_DataObject* LightApp_DataObject::componentObject() const
107 if ( !myCompObject ) {
108 SUIT_DataObject* compObj = 0; // for root object
110 if ( parent() && parent() == root() )
111 compObj = (SUIT_DataObject*)this; // for component-level objects
114 compObj = parent(); // for lower level objects
115 while ( compObj && compObj->parent() != root() )
116 compObj = compObj->parent();
118 LightApp_DataObject* that = (LightApp_DataObject*)this;
119 that->myCompObject = compObj;
124 /*!Get component type.*/
125 QString LightApp_DataObject::componentDataType() const
127 if ( myCompDataType.isEmpty() ) {
128 SUIT_DataObject* aCompObj = componentObject();
129 LightApp_ModuleObject* anObj = dynamic_cast<LightApp_ModuleObject*>( aCompObj );
131 CAM_DataModel* aModel = anObj->dataModel();
133 LightApp_DataObject* that = (LightApp_DataObject*)this;
134 that->myCompDataType = aModel->module()->name();
138 return myCompDataType;
143 /*!Constructor.Initialize by \a parent.*/
144 LightApp_ModuleObject::LightApp_ModuleObject( SUIT_DataObject* parent )
145 : CAM_RootObject( parent ),
146 CAM_DataObject( parent )
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 )
157 /*!Destructor. Do nothing.*/
158 LightApp_ModuleObject::~LightApp_ModuleObject()
162 /*!Returns module name */
163 QString LightApp_ModuleObject::name() const
165 return CAM_RootObject::name();
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 )
172 CAM_RootObject::insertChild(theObj, thePosition);
174 CAM_DataModel* aModel = dataModel();
176 LightApp_RootObject* aRoot = dynamic_cast<LightApp_RootObject*>(parent());
179 aRoot->study()->addComponent(aModel);