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