1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_Utils.cxx
23 // Author : Open CASCADE S.A.S.
27 #include "SMESHGUI_Utils.h"
31 // SALOME GUI includes
32 #include <SUIT_Desktop.h>
33 #include <SUIT_Session.h>
34 #include <SUIT_MessageBox.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <LightApp_SelectionMgr.h>
38 #include <SalomeApp_Application.h>
39 #include <SalomeApp_Module.h>
40 #include <SalomeApp_Study.h>
42 #include <SALOME_ListIO.hxx>
47 GetDesktop(const CAM_Module* theModule)
49 return theModule->application()->desktop();
52 LightApp_SelectionMgr*
53 GetSelectionMgr(const SalomeApp_Module* theModule)
55 return theModule->getApp()->selectionMgr();
59 GetResourceMgr( const SalomeApp_Module* )
61 return SUIT_Session::session()->resourceMgr();
65 GetCStudy(const SalomeApp_Study* theStudy)
67 return theStudy->studyDS();
71 DataOwnerToObject(const LightApp_DataOwnerPtr& theOwner)
73 CORBA::Object_var anObj;
75 const Handle(SALOME_InteractiveObject)& anIO = theOwner->IO();
78 _PTR(Study) aStudy = GetActiveStudyDocument();
79 _PTR(SObject) aSObj = aStudy->FindObjectID(anIO->getEntry());
80 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 QString& 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.toLatin1().data());
142 void SetValue (_PTR(SObject) theSObject, const QString& 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.toLatin1().data());
155 void setFileName (_PTR(SObject) theSObject, const QString& 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.toLatin1().data());
168 void setFileType (_PTR(SObject) theSObject, const QString& 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.toLatin1().data());
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 QString& theIOR)
217 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
218 (SUIT_Session::session()->activeApplication());
219 return app->orb()->string_to_object(theIOR.toLatin1().data());
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("SMESH_OBJECTS_SELECTED").arg(aNbSel);
239 _PTR(SObject) GetMeshOrSubmesh (_PTR(SObject) theSObject)
241 GEOM::GEOM_Object_var aShape = SObjectToInterface<GEOM::GEOM_Object>(theSObject);
242 if (!aShape->_is_nil()){ //It s a shape
243 return theSObject->GetFather();
245 _PTR(SObject) aSObject;
246 if (theSObject->ReferencedObject(aSObject)) {
247 aSObject = theSObject->GetFather();
248 return aSObject->GetFather();
250 return theSObject->GetFather();
253 void ModifiedMesh (_PTR(SObject) theSObject, bool theIsNotModif, bool isEmptyMesh)
255 _PTR(Study) aStudy = GetActiveStudyDocument();
256 if (aStudy->GetProperties()->IsLocked())
259 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
260 _PTR(GenericAttribute) anAttr =
261 aBuilder->FindOrCreateAttribute(theSObject,"AttributePixMap");
262 _PTR(AttributePixMap) aPixmap = anAttr;
264 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
265 } else if ( isEmptyMesh ) {
266 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
268 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_PARTIAL");
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");
282 } else if ( isEmptyMesh ) {
283 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
285 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_PARTIAL");
292 void ShowHelpFile (const QString& theHelpFileName)
294 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
296 SMESHGUI* gui = SMESHGUI::GetSMESHGUI();
297 app->onHelpContextModule(gui ? app->moduleName(gui->moduleName()) : QString(""),
301 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
302 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
303 arg(app->resourceMgr()->stringValue("ExternalBrowser",
305 arg(theHelpFileName));
308 } // end of namespace SMESH