1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
23 #include "SMESHGUI_Utils.h"
25 #include "OB_Browser.h"
27 #include "SUIT_Desktop.h"
28 #include "SUIT_Application.h"
29 #include "SUIT_Session.h"
31 #include "LightApp_SelectionMgr.h"
32 #include "SalomeApp_Application.h"
33 #include "SalomeApp_Module.h"
34 #include "SalomeApp_Study.h"
36 #include "SALOME_ListIO.hxx"
38 #include "SALOMEconfig.h"
39 #include CORBA_CLIENT_HEADER(GEOM_Gen)
41 #include "utilities.h"
43 //using namespace std;
48 GetDesktop(const CAM_Module* theModule)
50 return theModule->application()->desktop();
53 LightApp_SelectionMgr*
54 GetSelectionMgr(const SalomeApp_Module* theModule)
56 return theModule->getApp()->selectionMgr();
60 GetResourceMgr( const SalomeApp_Module* )
62 return SUIT_Session::session()->resourceMgr();
66 GetCStudy(const SalomeApp_Study* theStudy)
68 return theStudy->studyDS();
72 DataOwnerToObject(const LightApp_DataOwnerPtr& theOwner)
74 CORBA::Object_var anObj;
76 const Handle(SALOME_InteractiveObject)& anIO = theOwner->IO();
79 _PTR(Study) aStudy = GetActiveStudyDocument();
80 _PTR(SObject) aSObj = aStudy->FindObjectID(anIO->getEntry());
81 anObj = SObjectToObject(aSObj,aStudy);
89 SUIT_Study* GetActiveStudy()
91 SUIT_Application* app = SUIT_Session::session()->activeApplication();
93 return app->activeStudy();
98 SUIT_ViewWindow* GetActiveWindow()
100 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
101 (SUIT_Session::session()->activeApplication());
102 if (app && app->desktop() )
103 return app->desktop()->activeWindow();
108 _PTR(Study) GetActiveStudyDocument()
110 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
112 return aStudy->studyDS();
114 return _PTR(Study)();
117 _PTR(SObject) FindSObject (CORBA::Object_ptr theObject)
119 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
120 (SUIT_Session::session()->activeApplication());
121 if (app && !CORBA::is_nil(theObject)) {
122 if(_PTR(Study) aStudy = GetActiveStudyDocument()){
123 CORBA::String_var anIOR = app->orb()->object_to_string(theObject);
124 if (strcmp(anIOR.in(), "") != 0)
125 return aStudy->FindObjectIOR(anIOR.in());
128 return _PTR(SObject)();
131 void SetName (_PTR(SObject) theSObject, const char* theName)
133 _PTR(Study) aStudy = GetActiveStudyDocument();
134 if (aStudy->GetProperties()->IsLocked())
136 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
137 _PTR(GenericAttribute) anAttr =
138 aBuilder->FindOrCreateAttribute(theSObject, "AttributeName");
139 _PTR(AttributeName) aName = anAttr;
141 aName->SetValue(theName);
144 void SetValue (_PTR(SObject) theSObject, const char* theValue)
146 _PTR(Study) aStudy = GetActiveStudyDocument();
147 if (aStudy->GetProperties()->IsLocked())
149 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
150 _PTR(GenericAttribute) anAttr =
151 aBuilder->FindOrCreateAttribute(theSObject, "AttributeComment");
152 _PTR(AttributeComment) aComment = anAttr;
154 aComment->SetValue(theValue);
157 void setFileName (_PTR(SObject) theSObject, const char* theValue)
159 _PTR(Study) aStudy = GetActiveStudyDocument();
160 if (aStudy->GetProperties()->IsLocked())
162 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
163 _PTR(GenericAttribute) anAttr =
164 aBuilder->FindOrCreateAttribute(theSObject, "AttributeExternalFileDef");
165 _PTR(AttributeExternalFileDef) aFileName = anAttr;
167 aFileName->SetValue(theValue);
170 void setFileType (_PTR(SObject) theSObject, const char* theValue)
172 _PTR(Study) aStudy = GetActiveStudyDocument();
173 if (aStudy->GetProperties()->IsLocked())
175 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
176 _PTR(GenericAttribute) anAttr =
177 aBuilder->FindOrCreateAttribute(theSObject, "AttributeFileType");
178 _PTR(AttributeFileType) aFileType = anAttr;
180 aFileType->SetValue(theValue);
183 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject,
184 _PTR(Study) theStudy)
186 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
187 (SUIT_Session::session()->activeApplication());
189 _PTR(GenericAttribute) anAttr;
190 if (theSObject->FindAttribute(anAttr, "AttributeIOR")) {
191 _PTR(AttributeIOR) anIOR = anAttr;
192 CORBA::String_var aVal = anIOR->Value().c_str();
193 return app->orb()->string_to_object(aVal);
196 return CORBA::Object::_nil();
199 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject)
201 _PTR(Study) aStudy = GetActiveStudyDocument();
202 return SObjectToObject(theSObject,aStudy);
205 CORBA::Object_var IObjectToObject (const Handle(SALOME_InteractiveObject)& theIO)
207 if (!theIO.IsNull()) {
208 if (theIO->hasEntry()) {
209 _PTR(Study) aStudy = GetActiveStudyDocument();
210 _PTR(SObject) anObj = aStudy->FindObjectID(theIO->getEntry());
211 return SObjectToObject(anObj,aStudy);
214 return CORBA::Object::_nil();
217 CORBA::Object_var IORToObject (const char* theIOR)
219 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
220 (SUIT_Session::session()->activeApplication());
221 return app->orb()->string_to_object(theIOR);
224 int GetNameOfSelectedIObjects(LightApp_SelectionMgr* theMgr, QString& theName)
229 SALOME_ListIO selected;
230 theMgr->selectedObjects(selected);
231 int aNbSel = selected.Extent();
233 Handle(SALOME_InteractiveObject) anIObject = selected.First();
234 theName = anIObject->getName();
236 theName = QObject::tr("SMESH_OBJECTS_SELECTED").arg(aNbSel);
241 _PTR(SObject) GetMeshOrSubmesh (_PTR(SObject) theSObject)
243 GEOM::GEOM_Object_var aShape = SObjectToInterface<GEOM::GEOM_Object>(theSObject);
244 if (!aShape->_is_nil()){ //It s a shape
245 return theSObject->GetFather();
247 _PTR(SObject) aSObject;
248 if (theSObject->ReferencedObject(aSObject)) {
249 aSObject = theSObject->GetFather();
250 return aSObject->GetFather();
252 return theSObject->GetFather();
255 void ModifiedMesh (_PTR(SObject) theSObject, bool theIsRight)
257 _PTR(Study) aStudy = GetActiveStudyDocument();
258 if (aStudy->GetProperties()->IsLocked())
261 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
262 _PTR(GenericAttribute) anAttr =
263 aBuilder->FindOrCreateAttribute(theSObject,"AttributePixMap");
264 _PTR(AttributePixMap) aPixmap = anAttr;
266 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
268 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
271 _PTR(ChildIterator) anIter = aStudy->NewChildIterator(theSObject);
272 for (int i = 1; anIter->More(); anIter->Next(), i++) {
273 _PTR(SObject) aSObj = anIter->Value();
275 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSObj);
276 for (; anIter1->More(); anIter1->Next()) {
277 _PTR(SObject) aSObj1 = anIter1->Value();
278 anAttr = aBuilder->FindOrCreateAttribute(aSObj1, "AttributePixMap");
281 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
283 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
290 // void UpdateObjBrowser (bool)
292 // //SMESHGUI::activeStudy()->updateObjBrowser(true);
293 // //SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
294 // // (SUIT_Session::session()->activeApplication());
295 // //if (anApp) anApp->objectBrowser()->updateTree();
296 // SMESHGUI::GetSMESHGUI()->updateObjBrowser();