1 // Copyright (C) 2007-2008 CEA/DEN, EDF 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
21 #include "FILTERGUI_Utils.h"
23 #include "OB_Browser.h"
25 #include "SUIT_Desktop.h"
26 #include "SUIT_Application.h"
27 #include "SUIT_Session.h"
29 #include "LightApp_SelectionMgr.h"
30 #include "SalomeApp_Application.h"
31 #include "SalomeApp_Module.h"
32 #include "SalomeApp_Study.h"
34 #include "SALOME_ListIO.hxx"
36 #include "SALOMEconfig.h"
37 // #include CORBA_CLIENT_HEADER(GEOM_Gen)
39 #include "utilities.h"
41 //using namespace std;
46 GetDesktop(const CAM_Module* theModule)
48 return theModule->application()->desktop();
51 LightApp_SelectionMgr*
52 GetSelectionMgr(const SalomeApp_Module* theModule)
54 return theModule->getApp()->selectionMgr();
58 GetResourceMgr( const SalomeApp_Module* )
60 return SUIT_Session::session()->resourceMgr();
64 GetCStudy(const SalomeApp_Study* theStudy)
66 return theStudy->studyDS();
70 DataOwnerToObject(const LightApp_DataOwnerPtr& theOwner)
72 CORBA::Object_var anObj;
74 const Handle(SALOME_InteractiveObject)& anIO = theOwner->IO();
77 _PTR(Study) aStudy = GetActiveStudyDocument();
78 _PTR(SObject) aSObj = aStudy->FindObjectID(anIO->getEntry());
79 anObj = SObjectToObject(aSObj,aStudy);
87 SUIT_Study* GetActiveStudy()
89 SUIT_Application* app = SUIT_Session::session()->activeApplication();
91 return app->activeStudy();
96 SUIT_ViewWindow* GetActiveWindow()
98 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
99 (SUIT_Session::session()->activeApplication());
100 if (app && app->desktop() )
101 return app->desktop()->activeWindow();
106 _PTR(Study) GetActiveStudyDocument()
108 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
110 return aStudy->studyDS();
112 return _PTR(Study)();
115 _PTR(SObject) FindSObject (CORBA::Object_ptr theObject)
117 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
118 (SUIT_Session::session()->activeApplication());
119 if (app && !CORBA::is_nil(theObject)) {
120 if(_PTR(Study) aStudy = GetActiveStudyDocument()){
121 CORBA::String_var anIOR = app->orb()->object_to_string(theObject);
122 if (strcmp(anIOR.in(), "") != 0)
123 return aStudy->FindObjectIOR(anIOR.in());
126 return _PTR(SObject)();
129 void SetName (_PTR(SObject) theSObject, const char* theName)
131 _PTR(Study) aStudy = GetActiveStudyDocument();
132 if (aStudy->GetProperties()->IsLocked())
134 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
135 _PTR(GenericAttribute) anAttr =
136 aBuilder->FindOrCreateAttribute(theSObject, "AttributeName");
137 _PTR(AttributeName) aName = anAttr;
139 aName->SetValue(theName);
142 void SetValue (_PTR(SObject) theSObject, const char* theValue)
144 _PTR(Study) aStudy = GetActiveStudyDocument();
145 if (aStudy->GetProperties()->IsLocked())
147 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
148 _PTR(GenericAttribute) anAttr =
149 aBuilder->FindOrCreateAttribute(theSObject, "AttributeComment");
150 _PTR(AttributeComment) aComment = anAttr;
152 aComment->SetValue(theValue);
155 void setFileName (_PTR(SObject) theSObject, const char* theValue)
157 _PTR(Study) aStudy = GetActiveStudyDocument();
158 if (aStudy->GetProperties()->IsLocked())
160 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
161 _PTR(GenericAttribute) anAttr =
162 aBuilder->FindOrCreateAttribute(theSObject, "AttributeExternalFileDef");
163 _PTR(AttributeExternalFileDef) aFileName = anAttr;
165 aFileName->SetValue(theValue);
168 void setFileType (_PTR(SObject) theSObject, const char* theValue)
170 _PTR(Study) aStudy = GetActiveStudyDocument();
171 if (aStudy->GetProperties()->IsLocked())
173 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
174 _PTR(GenericAttribute) anAttr =
175 aBuilder->FindOrCreateAttribute(theSObject, "AttributeFileType");
176 _PTR(AttributeFileType) aFileType = anAttr;
178 aFileType->SetValue(theValue);
181 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject,
182 _PTR(Study) theStudy)
184 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
185 (SUIT_Session::session()->activeApplication());
187 _PTR(GenericAttribute) anAttr;
188 if (theSObject->FindAttribute(anAttr, "AttributeIOR")) {
189 _PTR(AttributeIOR) anIOR = anAttr;
190 CORBA::String_var aVal = anIOR->Value().c_str();
191 return app->orb()->string_to_object(aVal);
194 return CORBA::Object::_nil();
197 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject)
199 _PTR(Study) aStudy = GetActiveStudyDocument();
200 return SObjectToObject(theSObject,aStudy);
203 CORBA::Object_var IObjectToObject (const Handle(SALOME_InteractiveObject)& theIO)
205 if (!theIO.IsNull()) {
206 if (theIO->hasEntry()) {
207 _PTR(Study) aStudy = GetActiveStudyDocument();
208 _PTR(SObject) anObj = aStudy->FindObjectID(theIO->getEntry());
209 return SObjectToObject(anObj,aStudy);
212 return CORBA::Object::_nil();
215 CORBA::Object_var IORToObject (const char* theIOR)
217 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
218 (SUIT_Session::session()->activeApplication());
219 return app->orb()->string_to_object(theIOR);
222 int GetNameOfSelectedIObjects(LightApp_SelectionMgr* theMgr, QString& theName)
227 SALOME_ListIO selected;
228 theMgr->selectedObjects(selected);
229 int aNbSel = selected.Extent();
231 Handle(SALOME_InteractiveObject) anIObject = selected.First();
232 theName = anIObject->getName();
234 theName = QObject::tr("FILTER_OBJECTS_SELECTED").arg(aNbSel);
239 // void UpdateObjBrowser (bool)
241 // //FILTERGUI::activeStudy()->updateObjBrowser(true);
242 // //SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
243 // // (SUIT_Session::session()->activeApplication());
244 // //if (anApp) anApp->objectBrowser()->updateTree();
245 // FILTERGUI::GetSMESHGUI()->updateObjBrowser();