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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "SMESHGUI_Utils.h"
26 #include "OB_Browser.h"
28 #include "SUIT_Desktop.h"
29 #include "SUIT_Application.h"
30 #include "SUIT_Session.h"
31 #include "SUIT_MessageBox.h"
33 #include "LightApp_SelectionMgr.h"
34 #include "SalomeApp_Application.h"
35 #include "SalomeApp_Module.h"
36 #include "SalomeApp_Study.h"
38 #include "SALOME_ListIO.hxx"
40 #include "SALOMEconfig.h"
41 #include CORBA_CLIENT_HEADER(GEOM_Gen)
43 #include "utilities.h"
45 //using namespace std;
50 GetDesktop(const CAM_Module* theModule)
52 return theModule->application()->desktop();
55 LightApp_SelectionMgr*
56 GetSelectionMgr(const SalomeApp_Module* theModule)
58 return theModule->getApp()->selectionMgr();
62 GetResourceMgr( const SalomeApp_Module* )
64 return SUIT_Session::session()->resourceMgr();
68 GetCStudy(const SalomeApp_Study* theStudy)
70 return theStudy->studyDS();
74 DataOwnerToObject(const LightApp_DataOwnerPtr& theOwner)
76 CORBA::Object_var anObj;
78 const Handle(SALOME_InteractiveObject)& anIO = theOwner->IO();
81 _PTR(Study) aStudy = GetActiveStudyDocument();
82 _PTR(SObject) aSObj = aStudy->FindObjectID(anIO->getEntry());
83 anObj = SObjectToObject(aSObj,aStudy);
91 SUIT_Study* GetActiveStudy()
93 SUIT_Application* app = SUIT_Session::session()->activeApplication();
95 return app->activeStudy();
100 SUIT_ViewWindow* GetActiveWindow()
102 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
103 (SUIT_Session::session()->activeApplication());
104 if (app && app->desktop() )
105 return app->desktop()->activeWindow();
110 _PTR(Study) GetActiveStudyDocument()
112 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
114 return aStudy->studyDS();
116 return _PTR(Study)();
119 _PTR(SObject) FindSObject (CORBA::Object_ptr theObject)
121 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
122 (SUIT_Session::session()->activeApplication());
123 if (app && !CORBA::is_nil(theObject)) {
124 if(_PTR(Study) aStudy = GetActiveStudyDocument()){
125 CORBA::String_var anIOR = app->orb()->object_to_string(theObject);
126 if (strcmp(anIOR.in(), "") != 0)
127 return aStudy->FindObjectIOR(anIOR.in());
130 return _PTR(SObject)();
133 void SetName (_PTR(SObject) theSObject, const char* theName)
135 _PTR(Study) aStudy = GetActiveStudyDocument();
136 if (aStudy->GetProperties()->IsLocked())
138 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
139 _PTR(GenericAttribute) anAttr =
140 aBuilder->FindOrCreateAttribute(theSObject, "AttributeName");
141 _PTR(AttributeName) aName = anAttr;
143 aName->SetValue(theName);
146 void SetValue (_PTR(SObject) theSObject, const char* theValue)
148 _PTR(Study) aStudy = GetActiveStudyDocument();
149 if (aStudy->GetProperties()->IsLocked())
151 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
152 _PTR(GenericAttribute) anAttr =
153 aBuilder->FindOrCreateAttribute(theSObject, "AttributeComment");
154 _PTR(AttributeComment) aComment = anAttr;
156 aComment->SetValue(theValue);
159 void setFileName (_PTR(SObject) theSObject, const char* theValue)
161 _PTR(Study) aStudy = GetActiveStudyDocument();
162 if (aStudy->GetProperties()->IsLocked())
164 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
165 _PTR(GenericAttribute) anAttr =
166 aBuilder->FindOrCreateAttribute(theSObject, "AttributeExternalFileDef");
167 _PTR(AttributeExternalFileDef) aFileName = anAttr;
169 aFileName->SetValue(theValue);
172 void setFileType (_PTR(SObject) theSObject, const char* theValue)
174 _PTR(Study) aStudy = GetActiveStudyDocument();
175 if (aStudy->GetProperties()->IsLocked())
177 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
178 _PTR(GenericAttribute) anAttr =
179 aBuilder->FindOrCreateAttribute(theSObject, "AttributeFileType");
180 _PTR(AttributeFileType) aFileType = anAttr;
182 aFileType->SetValue(theValue);
185 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject,
186 _PTR(Study) theStudy)
188 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
189 (SUIT_Session::session()->activeApplication());
191 _PTR(GenericAttribute) anAttr;
192 if (theSObject->FindAttribute(anAttr, "AttributeIOR")) {
193 _PTR(AttributeIOR) anIOR = anAttr;
194 CORBA::String_var aVal = anIOR->Value().c_str();
195 return app->orb()->string_to_object(aVal);
198 return CORBA::Object::_nil();
201 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject)
203 _PTR(Study) aStudy = GetActiveStudyDocument();
204 return SObjectToObject(theSObject,aStudy);
207 CORBA::Object_var IObjectToObject (const Handle(SALOME_InteractiveObject)& theIO)
209 if (!theIO.IsNull()) {
210 if (theIO->hasEntry()) {
211 _PTR(Study) aStudy = GetActiveStudyDocument();
212 _PTR(SObject) anObj = aStudy->FindObjectID(theIO->getEntry());
213 return SObjectToObject(anObj,aStudy);
216 return CORBA::Object::_nil();
219 CORBA::Object_var IORToObject (const char* theIOR)
221 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
222 (SUIT_Session::session()->activeApplication());
223 return app->orb()->string_to_object(theIOR);
226 int GetNameOfSelectedIObjects(LightApp_SelectionMgr* theMgr, QString& theName)
231 SALOME_ListIO selected;
232 theMgr->selectedObjects(selected);
233 int aNbSel = selected.Extent();
235 Handle(SALOME_InteractiveObject) anIObject = selected.First();
236 theName = anIObject->getName();
238 theName = QObject::tr("SMESH_OBJECTS_SELECTED").arg(aNbSel);
243 _PTR(SObject) GetMeshOrSubmesh (_PTR(SObject) theSObject)
245 GEOM::GEOM_Object_var aShape = SObjectToInterface<GEOM::GEOM_Object>(theSObject);
246 if (!aShape->_is_nil()){ //It s a shape
247 return theSObject->GetFather();
249 _PTR(SObject) aSObject;
250 if (theSObject->ReferencedObject(aSObject)) {
251 aSObject = theSObject->GetFather();
252 return aSObject->GetFather();
254 return theSObject->GetFather();
257 void ModifiedMesh (_PTR(SObject) theSObject, bool theIsNotModif, bool isEmptyMesh)
259 _PTR(Study) aStudy = GetActiveStudyDocument();
260 if (aStudy->GetProperties()->IsLocked())
263 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
264 _PTR(GenericAttribute) anAttr =
265 aBuilder->FindOrCreateAttribute(theSObject,"AttributePixMap");
266 _PTR(AttributePixMap) aPixmap = anAttr;
268 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
269 } else if ( isEmptyMesh ) {
270 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
272 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_PARTIAL");
275 _PTR(ChildIterator) anIter = aStudy->NewChildIterator(theSObject);
276 for (int i = 1; anIter->More(); anIter->Next(), i++) {
277 _PTR(SObject) aSObj = anIter->Value();
279 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSObj);
280 for (; anIter1->More(); anIter1->Next()) {
281 _PTR(SObject) aSObj1 = anIter1->Value();
282 anAttr = aBuilder->FindOrCreateAttribute(aSObj1, "AttributePixMap");
285 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
286 } else if ( isEmptyMesh ) {
287 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
289 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_PARTIAL");
296 void ShowHelpFile (QString theHelpFileName)
298 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
300 SMESHGUI* gui = SMESHGUI::GetSMESHGUI();
301 app->onHelpContextModule(gui ? app->moduleName(gui->moduleName()) : QString(""),
305 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
306 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
307 arg(app->resourceMgr()->stringValue("ExternalBrowser", "application")).arg(theHelpFileName),
308 QObject::tr("BUT_OK"));
312 // void UpdateObjBrowser (bool)
314 // //SMESHGUI::activeStudy()->updateObjBrowser(true);
315 // //SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
316 // // (SUIT_Session::session()->activeApplication());
317 // //if (anApp) anApp->objectBrowser()->updateTree();
318 // SMESHGUI::GetSMESHGUI()->updateObjBrowser();