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 "SalomeApp_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 SalomeApp_SelectionMgr*
54 GetSelectionMgr(const SalomeApp_Module* theModule)
56 return theModule->getApp()->selectionMgr();
61 GetCStudy(const SalomeApp_Study* theStudy)
63 return theStudy->studyDS();
67 DataOwnerToObject(const SalomeApp_DataOwnerPtr& theOwner)
69 CORBA::Object_var anObj;
71 const Handle(SALOME_InteractiveObject)& anIO = theOwner->IO();
74 _PTR(Study) aStudy = GetActiveStudyDocument();
75 _PTR(SObject) aSObj = aStudy->FindObjectID(anIO->getEntry());
76 anObj = SObjectToObject(aSObj,aStudy);
84 SUIT_Study* GetActiveStudy()
86 SUIT_Application* app = SUIT_Session::session()->activeApplication();
88 return app->activeStudy();
93 SUIT_ViewWindow* GetActiveWindow()
95 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
96 (SUIT_Session::session()->activeApplication());
97 if (app && app->activeViewManager())
98 return app->activeViewManager()->getActiveView();
103 _PTR(Study) GetActiveStudyDocument()
105 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
107 return aStudy->studyDS();
109 return _PTR(Study)();
112 _PTR(SObject) FindSObject (CORBA::Object_ptr theObject)
114 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
115 (SUIT_Session::session()->activeApplication());
116 if (app && !CORBA::is_nil(theObject)) {
117 if(_PTR(Study) aStudy = GetActiveStudyDocument()){
118 CORBA::String_var anIOR = app->orb()->object_to_string(theObject);
119 if (strcmp(anIOR.in(), "") != 0)
120 return aStudy->FindObjectIOR(anIOR.in());
123 return _PTR(SObject)();
126 void SetName (_PTR(SObject) theSObject, const char* theName)
128 _PTR(Study) aStudy = GetActiveStudyDocument();
129 if (aStudy->GetProperties()->IsLocked())
131 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
132 _PTR(GenericAttribute) anAttr =
133 aBuilder->FindOrCreateAttribute(theSObject, "AttributeName");
134 _PTR(AttributeName) aName = anAttr;
136 aName->SetValue(theName);
139 void SetValue (_PTR(SObject) theSObject, const char* theValue)
141 _PTR(Study) aStudy = GetActiveStudyDocument();
142 if (aStudy->GetProperties()->IsLocked())
144 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
145 _PTR(GenericAttribute) anAttr =
146 aBuilder->FindOrCreateAttribute(theSObject, "AttributeComment");
147 _PTR(AttributeComment) aComment = anAttr;
149 aComment->SetValue(theValue);
152 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject,
153 _PTR(Study) theStudy)
155 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
156 (SUIT_Session::session()->activeApplication());
158 _PTR(GenericAttribute) anAttr;
159 if (theSObject->FindAttribute(anAttr, "AttributeIOR")) {
160 _PTR(AttributeIOR) anIOR = anAttr;
161 CORBA::String_var aVal = anIOR->Value().c_str();
162 return app->orb()->string_to_object(aVal);
165 return CORBA::Object::_nil();
168 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject)
170 _PTR(Study) aStudy = GetActiveStudyDocument();
171 return SObjectToObject(theSObject,aStudy);
174 CORBA::Object_var IObjectToObject (const Handle(SALOME_InteractiveObject)& theIO)
176 if (!theIO.IsNull()) {
177 if (theIO->hasEntry()) {
178 _PTR(Study) aStudy = GetActiveStudyDocument();
179 _PTR(SObject) anObj = aStudy->FindObjectID(theIO->getEntry());
180 return SObjectToObject(anObj,aStudy);
183 return CORBA::Object::_nil();
186 CORBA::Object_var IORToObject (const char* theIOR)
188 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
189 (SUIT_Session::session()->activeApplication());
190 return app->orb()->string_to_object(theIOR);
193 int GetNameOfSelectedIObjects(SalomeApp_SelectionMgr* theMgr, QString& theName)
198 SALOME_ListIO selected;
199 theMgr->selectedObjects(selected);
200 int aNbSel = selected.Extent();
202 Handle(SALOME_InteractiveObject) anIObject = selected.First();
203 theName = anIObject->getName();
205 theName = QObject::tr("SMESH_OBJECTS_SELECTED").arg(aNbSel);
210 _PTR(SObject) GetMeshOrSubmesh (_PTR(SObject) theSObject)
212 GEOM::GEOM_Object_var aShape = SObjectToInterface<GEOM::GEOM_Object>(theSObject);
213 if (!aShape->_is_nil()){ //It s a shape
214 return theSObject->GetFather();
216 _PTR(SObject) aSObject;
217 if (theSObject->ReferencedObject(aSObject)) {
218 aSObject = theSObject->GetFather();
219 return aSObject->GetFather();
221 return theSObject->GetFather();
224 void ModifiedMesh (_PTR(SObject) theSObject, bool theIsRight)
226 _PTR(Study) aStudy = GetActiveStudyDocument();
227 if (aStudy->GetProperties()->IsLocked())
230 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
231 _PTR(GenericAttribute) anAttr =
232 aBuilder->FindOrCreateAttribute(theSObject,"AttributePixMap");
233 _PTR(AttributePixMap) aPixmap = anAttr;
235 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
237 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
240 _PTR(ChildIterator) anIter = aStudy->NewChildIterator(theSObject);
241 for (int i = 1; anIter->More(); anIter->Next(), i++) {
242 _PTR(SObject) aSObj = anIter->Value();
244 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSObj);
245 for (; anIter1->More(); anIter1->Next()) {
246 _PTR(SObject) aSObj1 = anIter1->Value();
247 anAttr = aBuilder->FindOrCreateAttribute(aSObj1, "AttributePixMap");
250 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
252 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
259 // void UpdateObjBrowser (bool)
261 // //SMESHGUI::activeStudy()->updateObjBrowser(true);
262 // //SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>
263 // // (SUIT_Session::session()->activeApplication());
264 // //if (anApp) anApp->objectBrowser()->updateTree();
265 // SMESHGUI::GetSMESHGUI()->updateObjBrowser();