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