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 "QAD_Desktop.h"
27 #include "SALOMEconfig.h"
28 #include CORBA_CLIENT_HEADER(GEOM_Gen)
29 #include CORBA_CLIENT_HEADER(SALOMEDS_Attributes)
31 #include "utilities.h"
37 QAD_Study* GetActiveStudy(){
38 if(QAD_Desktop* aDesktop = QAD_Application::getDesktop())
39 return aDesktop->getActiveStudy();
44 QAD_StudyFrame* GetActiveStudyFrame(){
45 if(QAD_Study* aStudy = GetActiveStudy())
46 return aStudy->getActiveStudyFrame();
51 SALOMEDS::Study_var GetActiveStudyDocument(){
52 if(QAD_Study* aStudy = GetActiveStudy())
53 return aStudy->getStudyDocument();
54 return SALOMEDS::Study::_nil();
58 SALOMEDS::SObject_var FindSObject(CORBA::Object_ptr theObject){
59 if(!CORBA::is_nil(theObject)){
60 SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
61 CORBA::String_var anIOR = aStudy->ConvertObjectToIOR(theObject);
62 if(strcmp(anIOR.in(),"") != 0)
63 return aStudy->FindObjectIOR(anIOR);
65 return SALOMEDS::SObject::_nil();
69 void SetName(SALOMEDS::SObject_ptr theSObject, const char* theName){
70 using namespace SALOMEDS;
71 Study_var aStudy = GetActiveStudyDocument();
72 if(aStudy->GetProperties()->IsLocked())
74 StudyBuilder_var aBuilder = aStudy->NewBuilder();
75 GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute(theSObject,"AttributeName");
76 AttributeName_var aName = AttributeName::_narrow(anAttr);
78 aName->SetValue(theName);
81 void SetValue(SALOMEDS::SObject_ptr theSObject, const char* theValue){
82 using namespace SALOMEDS;
83 Study_var aStudy = GetActiveStudyDocument();
84 if(aStudy->GetProperties()->IsLocked())
86 StudyBuilder_var aBuilder = aStudy->NewBuilder();
87 GenericAttribute_var anAttr = aBuilder->FindOrCreateAttribute(theSObject,"AttributeComment");
88 AttributeComment_var aComment = AttributeComment::_narrow(anAttr);
89 if(!aComment->_is_nil())
90 aComment->SetValue(theValue);
94 CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr theSObject,
95 SALOMEDS::Study_ptr theStudy)
97 if(!theSObject->_is_nil()){
98 SALOMEDS::GenericAttribute_var anAttr;
99 if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
100 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
101 CORBA::String_var aVal = anIOR->Value();
102 return theStudy->ConvertIORToObject(aVal.in());
105 return CORBA::Object::_nil();
109 CORBA::Object_var SObjectToObject(SALOMEDS::SObject_ptr theSObject){
110 SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
111 return SObjectToObject(theSObject,aStudy);
115 CORBA::Object_var IObjectToObject(const Handle(SALOME_InteractiveObject)& theIO){
117 if(theIO->hasEntry()){
118 SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
119 SALOMEDS::SObject_var anObj = aStudy->FindObjectID(theIO->getEntry());
120 return SObjectToObject(anObj,aStudy);
123 return CORBA::Object::_nil();
127 CORBA::Object_var IORToObject(const char* theIOR){
128 SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
129 return aStudy->ConvertIORToObject(theIOR);
133 int GetNameOfSelectedIObjects(SALOME_Selection* theSel, QString& theName)
135 int aNbSel = theSel->IObjectCount();
137 Handle(SALOME_InteractiveObject) anIObject = theSel->firstIObject();
138 theName = anIObject->getName();
140 theName = QObject::tr("SMESH_OBJECTS_SELECTED").arg(aNbSel);
146 SALOMEDS::SObject_var GetMeshOrSubmesh(SALOMEDS::SObject_ptr theSObject){
147 GEOM::GEOM_Object_var aShape = SObjectToInterface<GEOM::GEOM_Object>(theSObject);
148 if(!aShape->_is_nil()){ //It s a shape
149 return theSObject->GetFather();
151 SALOMEDS::SObject_var aSObject;
152 if(theSObject->ReferencedObject(aSObject)){
153 aSObject = theSObject->GetFather();
154 return aSObject->GetFather();
156 return theSObject->GetFather();
160 void ModifiedMesh(SALOMEDS::SObject_ptr theSObject, bool theIsRight)
162 SALOMEDS::Study_var aStudy = GetActiveStudyDocument();
163 if(aStudy->GetProperties()->IsLocked())
166 SALOMEDS::StudyBuilder_var aBuilder = aStudy->NewBuilder();
167 SALOMEDS::GenericAttribute_var anAttr =
168 aBuilder->FindOrCreateAttribute(theSObject,"AttributePixMap");
169 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
171 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
173 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");
176 SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theSObject);
177 for (int i = 1; anIter->More(); anIter->Next(), i++) {
178 SALOMEDS::SObject_var aSObj = anIter->Value();
180 SALOMEDS::ChildIterator_var anIter1 = aStudy->NewChildIterator(aSObj);
181 for(; anIter1->More(); anIter1->Next()){
182 SALOMEDS::SObject_var aSObj1 = anIter1->Value();
183 anAttr = aBuilder->FindOrCreateAttribute(aSObj1,"AttributePixMap");
184 aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr);
186 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH");
188 aPixmap->SetPixMap("ICON_SMESH_TREE_MESH_WARN");