1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_Utils.cxx
24 // Author : Open CASCADE S.A.S.
27 #include "SMESHGUI_Utils.h"
30 #include <SMDS_MeshNode.hxx>
31 #include <SMDS_MeshFace.hxx>
33 // SALOME GUI includes
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
39 #include <LightApp_SelectionMgr.h>
40 #include <SalomeApp_Application.h>
41 #include <SalomeApp_Module.h>
42 #include <SalomeApp_Study.h>
44 #include <SALOME_ListIO.hxx>
48 #include <TColgp_Array1OfXYZ.hxx>
53 GetDesktop(const CAM_Module* theModule)
55 return theModule->application()->desktop();
58 LightApp_SelectionMgr*
59 GetSelectionMgr(const SalomeApp_Module* theModule)
61 return theModule->getApp()->selectionMgr();
65 GetResourceMgr( const SalomeApp_Module* )
67 return SUIT_Session::session()->resourceMgr();
71 GetCStudy(const SalomeApp_Study* theStudy)
73 return theStudy->studyDS();
77 DataOwnerToObject(const LightApp_DataOwnerPtr& theOwner)
79 CORBA::Object_var anObj;
81 const Handle(SALOME_InteractiveObject)& anIO = theOwner->IO();
84 _PTR(Study) aStudy = GetActiveStudyDocument();
85 _PTR(SObject) aSObj = aStudy->FindObjectID(anIO->getEntry());
86 anObj = SObjectToObject(aSObj,aStudy);
93 SUIT_Study* GetActiveStudy()
95 SUIT_Application* app = SUIT_Session::session()->activeApplication();
97 return app->activeStudy();
102 SUIT_ViewWindow* GetActiveWindow()
104 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
105 (SUIT_Session::session()->activeApplication());
106 if (app && app->desktop() )
107 return app->desktop()->activeWindow();
112 _PTR(Study) GetActiveStudyDocument()
114 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>(GetActiveStudy());
116 return aStudy->studyDS();
118 return _PTR(Study)();
121 _PTR(SObject) FindSObject (CORBA::Object_ptr theObject)
123 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
124 (SUIT_Session::session()->activeApplication());
125 if (app && !CORBA::is_nil(theObject)) {
126 if(_PTR(Study) aStudy = GetActiveStudyDocument()){
127 CORBA::String_var anIOR = app->orb()->object_to_string(theObject);
128 if (strcmp(anIOR.in(), "") != 0)
129 return aStudy->FindObjectIOR(anIOR.in());
132 return _PTR(SObject)();
135 void SetName (_PTR(SObject) theSObject, const QString& theName)
137 _PTR(Study) aStudy = GetActiveStudyDocument();
138 if (aStudy->GetProperties()->IsLocked())
140 SMESHGUI::GetSMESHGen()->SetName(theSObject->GetIOR().c_str(), theName.toLatin1().data());
143 void SetValue (_PTR(SObject) theSObject, const QString& theValue)
145 _PTR(Study) aStudy = GetActiveStudyDocument();
146 if (aStudy->GetProperties()->IsLocked())
148 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
149 _PTR(GenericAttribute) anAttr =
150 aBuilder->FindOrCreateAttribute(theSObject, "AttributeComment");
151 _PTR(AttributeComment) aComment = anAttr;
153 aComment->SetValue(theValue.toLatin1().data());
156 void setFileName (_PTR(SObject) theSObject, const QString& theValue)
158 _PTR(Study) aStudy = GetActiveStudyDocument();
159 if (aStudy->GetProperties()->IsLocked())
161 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
162 _PTR(GenericAttribute) anAttr =
163 aBuilder->FindOrCreateAttribute(theSObject, "AttributeExternalFileDef");
164 _PTR(AttributeExternalFileDef) aFileName = anAttr;
166 aFileName->SetValue(theValue.toLatin1().data());
169 void setFileType (_PTR(SObject) theSObject, const QString& theValue)
171 _PTR(Study) aStudy = GetActiveStudyDocument();
172 if (aStudy->GetProperties()->IsLocked())
174 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
175 _PTR(GenericAttribute) anAttr =
176 aBuilder->FindOrCreateAttribute(theSObject, "AttributeFileType");
177 _PTR(AttributeFileType) aFileType = anAttr;
179 aFileType->SetValue(theValue.toLatin1().data());
182 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject,
183 _PTR(Study) theStudy)
185 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
186 (SUIT_Session::session()->activeApplication());
188 _PTR(GenericAttribute) anAttr;
189 if (theSObject->FindAttribute(anAttr, "AttributeIOR")) {
190 _PTR(AttributeIOR) anIOR = anAttr;
191 CORBA::String_var aVal = anIOR->Value().c_str();
192 return app->orb()->string_to_object(aVal);
195 return CORBA::Object::_nil();
198 CORBA::Object_var SObjectToObject (_PTR(SObject) theSObject)
200 _PTR(Study) aStudy = GetActiveStudyDocument();
201 return SObjectToObject(theSObject,aStudy);
204 CORBA::Object_var IObjectToObject (const Handle(SALOME_InteractiveObject)& theIO)
206 if (!theIO.IsNull()) {
207 if (theIO->hasEntry()) {
208 _PTR(Study) aStudy = GetActiveStudyDocument();
209 _PTR(SObject) anObj = aStudy->FindObjectID(theIO->getEntry());
210 return SObjectToObject(anObj,aStudy);
213 return CORBA::Object::_nil();
216 CORBA::Object_var IORToObject (const QString& theIOR)
218 SalomeApp_Application* app = dynamic_cast<SalomeApp_Application*>
219 (SUIT_Session::session()->activeApplication());
220 return app->orb()->string_to_object(theIOR.toLatin1().data());
223 int GetNameOfSelectedIObjects(LightApp_SelectionMgr* theMgr, QString& theName)
228 SALOME_ListIO selected;
229 theMgr->selectedObjects(selected);
230 int aNbSel = selected.Extent();
232 Handle(SALOME_InteractiveObject) anIObject = selected.First();
233 theName = anIObject->getName();
235 theName = QObject::tr("SMESH_OBJECTS_SELECTED").arg(aNbSel);
240 _PTR(SObject) GetMeshOrSubmesh (_PTR(SObject) theSObject)
242 GEOM::GEOM_Object_var aShape = SObjectToInterface<GEOM::GEOM_Object>(theSObject);
243 if (!aShape->_is_nil()){ //It s a shape
244 return theSObject->GetFather();
246 _PTR(SObject) aSObject;
247 if (theSObject->ReferencedObject(aSObject)) {
248 aSObject = theSObject->GetFather();
249 return aSObject->GetFather();
251 return theSObject->GetFather();
254 void ModifiedMesh (_PTR(SObject) theSObject, bool theIsNotModif, bool isEmptyMesh)
256 _PTR(Study) aStudy = GetActiveStudyDocument();
257 if (aStudy->GetProperties()->IsLocked())
260 _PTR(StudyBuilder) aBuilder = aStudy->NewBuilder();
261 _PTR(GenericAttribute) anAttr =
262 aBuilder->FindOrCreateAttribute(theSObject,"AttributePixMap");
263 _PTR(AttributePixMap) aPixmap = anAttr;
265 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
266 } else if ( isEmptyMesh ) {
267 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
269 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_PARTIAL");
272 _PTR(ChildIterator) anIter = aStudy->NewChildIterator(theSObject);
273 for (int i = 1; anIter->More(); anIter->Next(), i++) {
274 _PTR(SObject) aSObj = anIter->Value();
276 _PTR(ChildIterator) anIter1 = aStudy->NewChildIterator(aSObj);
277 for ( ; anIter1->More(); anIter1->Next()) {
278 _PTR(SObject) aSObj1 = anIter1->Value();
279 anAttr = aBuilder->FindOrCreateAttribute(aSObj1, "AttributePixMap");
282 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
283 } else if ( isEmptyMesh ) {
284 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
286 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_PARTIAL");
293 void ShowHelpFile (const QString& theHelpFileName)
295 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
297 SMESHGUI* gui = SMESHGUI::GetSMESHGUI();
298 app->onHelpContextModule(gui ? app->moduleName(gui->moduleName()) : QString(""),
302 SUIT_MessageBox::warning(0, QObject::tr("WRN_WARNING"),
303 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
304 arg(app->resourceMgr()->stringValue("ExternalBrowser",
306 arg(theHelpFileName));
310 //=======================================================================
312 Return normale to a given face
314 //=======================================================================
315 gp_XYZ getNormale( const SMDS_MeshFace* theFace )
318 int aNbNode = theFace->NbNodes();
319 TColgp_Array1OfXYZ anArrOfXYZ(1,4);
320 SMDS_ElemIteratorPtr aNodeItr = theFace->nodesIterator();
322 for ( ; aNodeItr->more() && i <= 4; i++ ) {
323 SMDS_MeshNode* aNode = (SMDS_MeshNode*)aNodeItr->next();
324 anArrOfXYZ.SetValue(i, gp_XYZ( aNode->X(), aNode->Y(), aNode->Z() ) );
327 gp_XYZ q1 = anArrOfXYZ.Value(2) - anArrOfXYZ.Value(1);
328 gp_XYZ q2 = anArrOfXYZ.Value(3) - anArrOfXYZ.Value(1);
331 gp_XYZ q3 = anArrOfXYZ.Value(4) - anArrOfXYZ.Value(1);
334 double len = n.Modulus();
340 } // end of namespace SMESH