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 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject,
158 _PTR(Study) theStudy)
160 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
161 (SUIT_Session::session()->activeApplication());
163 _PTR(GenericAttribute) anAttr;
164 if (theSObject->FindAttribute(anAttr, "AttributeIOR")) {
165 _PTR(AttributeIOR) anIOR = anAttr;
166 CORBA::String_var aVal = anIOR->Value().c_str();
167 return app->orb()->string_to_object(aVal);
170 return CORBA::Object::_nil();
173 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject)
175 _PTR(Study) aStudy = GetActiveStudyDocument();
176 return SObjectToObject(theSObject,aStudy);
179 CORBA::Object_var IObjectToObject (const Handle(SALOME_InteractiveObject)& theIO)
181 if (!theIO.IsNull()) {
182 if (theIO->hasEntry()) {
183 _PTR(Study) aStudy = GetActiveStudyDocument();
184 _PTR(SObject) anObj = aStudy->FindObjectID(theIO->getEntry());
185 return SObjectToObject(anObj,aStudy);
188 return CORBA::Object::_nil();
191 CORBA::Object_var IORToObject (const char* theIOR)
193 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
194 (SUIT_Session::session()->activeApplication());
195 return app->orb()->string_to_object(theIOR);
198 int GetNameOfSelectedIObjects(LightApp_SelectionMgr* theMgr, QString& theName)
203 SALOME_ListIO selected;
204 theMgr->selectedObjects(selected);
205 int aNbSel = selected.Extent();
207 Handle(SALOME_InteractiveObject) anIObject = selected.First();
208 theName = anIObject->getName();
210 theName = QObject::tr("SMESH_OBJECTS_SELECTED").arg(aNbSel);
215 _PTR(SObject) GetMeshOrSubmesh (_PTR(SObject) theSObject)
217 GEOM::GEOM_Object_var aShape = SObjectToInterface<GEOM::GEOM_Object>(theSObject);
218 if (!aShape->_is_nil()){ //It s a shape
219 return theSObject->GetFather();
221 _PTR(SObject) aSObject;
222 if (theSObject->ReferencedObject(aSObject)) {
223 aSObject = theSObject->GetFather();
224 return aSObject->GetFather();
226 return theSObject->GetFather();
229 void ModifiedMesh (_PTR(SObject) theSObject, bool theIsRight)
231 _PTR(Study) aStudy = GetActiveStudyDocument();
232 if (aStudy->GetProperties()->IsLocked())
235 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
236 _PTR(GenericAttribute) anAttr =
237 aBuilder->FindOrCreateAttribute(theSObject,"AttributePixMap");
238 _PTR(AttributePixMap) aPixmap = anAttr;
240 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
242 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
245 _PTR(ChildIterator) anIter = aStudy->NewChildIterator(theSObject);
246 for (int i = 1; anIter->More(); anIter->Next(), i++) {
247 _PTR(SObject) aSObj = anIter->Value();
249 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSObj);
250 for (; anIter1->More(); anIter1->Next()) {
251 _PTR(SObject) aSObj1 = anIter1->Value();
252 anAttr = aBuilder->FindOrCreateAttribute(aSObj1, "AttributePixMap");
255 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
257 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
264 // void UpdateObjBrowser (bool)
266 // //SMESHGUI::activeStudy()->updateObjBrowser(true);
267 // //SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
268 // // (SUIT_Session::session()->activeApplication());
269 // //if (anApp) anApp->objectBrowser()->updateTree();
270 // SMESHGUI::GetSMESHGUI()->updateObjBrowser();