Salome HOME
5bfa0adfae0e15a9547cfd6068596766bb0f0a76
[modules/gui.git] / src / SalomeApp / SalomeApp_Module.cxx
1 //  Copyright (C) 2007-2008  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 // File:      SalomeApp_Module.cxx
23 // Created:   10/25/2004 11:39:56 AM
24 // Author:    Sergey LITONIN
25 //
26 #include "SalomeApp_Module.h"
27 #include "SalomeApp_DataModel.h"
28 #include "SalomeApp_Application.h"
29 #include "SalomeApp_Study.h"
30
31 #include "LightApp_Selection.h"
32
33 #include "CAM_DataModel.h"
34
35 // temporary commented
36 //#include "OB_Browser.h"
37
38 #include <SALOME_ListIO.hxx>
39 #include <SALOME_ListIteratorOfListIO.hxx>
40 #include <SALOME_InteractiveObject.hxx>
41
42 #include <SUIT_Session.h>
43
44 #include <QString>
45
46 /*!Constructor.*/
47 SalomeApp_Module::SalomeApp_Module( const QString& name )
48 : LightApp_Module( name )
49 {
50 }
51
52 /*!Destructor.*/
53 SalomeApp_Module::~SalomeApp_Module()
54 {
55 }
56
57 /*!Gets application.*/
58 SalomeApp_Application* SalomeApp_Module::getApp() const
59 {
60   return (SalomeApp_Application*)application();
61 }
62
63 /*!Create new instance of data model and return it.*/
64 CAM_DataModel* SalomeApp_Module::createDataModel()
65 {
66   return new SalomeApp_DataModel(this);
67 }
68
69 /*!Create and return instance of LightApp_Selection.*/
70 LightApp_Selection* SalomeApp_Module::createSelection() const
71 {
72   return LightApp_Module::createSelection();
73 }
74
75 /*!
76   Converts objects-containers to list of objects, those are contained
77   Other objects must be added without conversion
78   \param source - source list of objects
79   \param dest - list of converted objects
80 */
81 void SalomeApp_Module::extractContainers( const SALOME_ListIO& source, SALOME_ListIO& dest ) const
82 {
83   SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>( SUIT_Session::session()->activeApplication()->activeStudy() );
84   if( !study )
85   {
86     dest = source;
87     return;
88   }
89
90   SALOME_ListIteratorOfListIO anIt( source );
91   for( ; anIt.More(); anIt.Next() )
92   {
93     Handle( SALOME_InteractiveObject ) obj = anIt.Value();
94     if( obj->hasEntry() )
95     {
96       _PTR(SObject) SO = study->studyDS()->FindObjectID( obj->getEntry() );
97       if( SO && QString( SO->GetID().c_str() ) == SO->GetFatherComponent()->GetID().c_str() )
98       { //component is selected
99         _PTR(SComponent) SC( SO->GetFatherComponent() );
100         _PTR(ChildIterator) anIter ( study->studyDS()->NewChildIterator( SC ) );
101         anIter->InitEx( true );
102         while( anIter->More() )
103         {
104           _PTR(SObject) valSO ( anIter->Value() );
105           _PTR(SObject) refSO;
106           if( !valSO->ReferencedObject( refSO ) )
107           {
108             QString id = valSO->GetID().c_str(),
109                     comp = SC->ComponentDataType().c_str(),
110                     val = valSO->GetName().c_str();
111
112             Handle( SALOME_InteractiveObject ) new_obj =
113               new SALOME_InteractiveObject( id.toLatin1(), comp.toLatin1(), val.toLatin1() );
114             dest.Append( new_obj );
115           }
116           anIter->Next();
117         }
118         continue;
119       }
120     }
121     dest.Append( obj );
122   }
123 }
124
125 /*!
126  * \brief Virtual public
127  *
128  * This method is called just before the study document is saved, so the module has a possibility
129  * to store visual parameters in AttributeParameter attribue(s)
130  */
131 void SalomeApp_Module::storeVisualParameters(int savePoint)
132 {
133 }
134
135 /*!
136  * \brief Virtual public
137  *
138  * This method is called after the study document is opened, so the module has a possibility to restore
139  * visual parameters
140  */
141 void SalomeApp_Module::restoreVisualParameters(int savePoint)
142 {
143 }
144