Salome HOME
Portation on new based dialog
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_StandardMeshInfosOp.cxx
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
21 //
22 //
23 //
24 //  File   : SMESHGUI_StandardMeshInfosOp.cxx
25 //  Author : Alexander SOLOVYOV
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESHGUI_StandardMeshInfosOp.h"
30 #include <SMESHGUI_StandardMeshInfosDlg.h>
31 #include <SMESHGUI_Utils.h>
32
33 #include <SMESH.hxx>
34 #include <SMESH_TypeFilter.hxx>
35
36 #include <SUIT_OverrideCursor.h>
37
38 #include CORBA_SERVER_HEADER(SMESH_Gen)
39 #include CORBA_SERVER_HEADER(SMESH_Group)
40
41 #include <SALOMEDS_SObject.hxx>
42
43 //=================================================================================
44 // function : SMESHGUI_StandardMeshInfosOp()
45 // purpose  : constructor
46 //=================================================================================
47 SMESHGUI_StandardMeshInfosOp::SMESHGUI_StandardMeshInfosOp()
48 : SMESHGUI_SelectionOp(),
49   myDlg( 0 )
50 {
51 }
52
53 //=================================================================================
54 // function : ~SMESHGUI_StandardMeshInfosOp()
55 // purpose  : destructor
56 //=================================================================================
57 SMESHGUI_StandardMeshInfosOp::~SMESHGUI_StandardMeshInfosOp()
58 {
59   if( myDlg )
60     delete myDlg;
61 }
62
63 //=================================================================================
64 // function : dlg
65 // purpose  : 
66 //=================================================================================
67 SalomeApp_Dialog* SMESHGUI_StandardMeshInfosOp::dlg() const
68 {
69   return myDlg;
70 }
71
72 //=================================================================================
73 // function : startOperation
74 // purpose  :
75 //=================================================================================
76 void SMESHGUI_StandardMeshInfosOp::startOperation()
77 {
78   if( !myDlg )
79     myDlg = new SMESHGUI_StandardMeshInfosDlg();
80
81   SMESHGUI_SelectionOp::startOperation();
82
83   myDlg->show();
84 }
85
86 //=================================================================================
87 // function : createFilter
88 // purpose  :
89 //=================================================================================
90 SUIT_SelectionFilter* SMESHGUI_StandardMeshInfosOp::createFilter( const int ) const
91 {
92   return new SMESH_TypeFilter( MESH );
93 }
94
95 //=================================================================================
96 // function : fillMeshInfos
97 // purpose  :
98 //=================================================================================
99 void SMESHGUI_StandardMeshInfosOp::fillMeshInfos()
100 {
101   if( !myDlg )
102     return;
103     
104   SUIT_OverrideCursor wc;
105
106   QStringList ids; myDlg->selectedObject( 0, ids );
107   if( ids.count()==0 )
108   {
109     myDlg->setInfo( "" );
110     return;
111   }
112
113   _PTR(SObject) SO = studyDS()->FindObjectID( ids.first() ), anObj;
114   if( !SO )
115   {
116     myDlg->setInfo( "" );
117     return;
118   }
119     
120   SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _CAST(SObject,SO)->GetObject() );
121
122   if( aMesh->_is_nil() )
123   {
124     myDlg->setInfo( "" );
125     return;
126   }
127
128
129   QString anInfo;
130   int aNbNodes =   (int)aMesh->NbNodes();
131   int aNbEdges =   (int)aMesh->NbEdges();
132   int aNbFaces =   (int)aMesh->NbFaces();
133   int aNbVolumes = (int)aMesh->NbVolumes();
134
135   int aDimension = 0;
136   double aNbDimElements = 0;
137   if( aNbVolumes > 0 )
138   {
139     aNbDimElements = aNbVolumes;
140     aDimension = 3;
141   }
142   else if( aNbFaces > 0 )
143   {
144     aNbDimElements = aNbFaces;
145     aDimension = 2;
146   }
147   else if( aNbEdges > 0 )
148   {
149     aNbDimElements = aNbEdges;
150     aDimension = 1;
151   }
152   else if( aNbNodes > 0 )
153   {
154     aNbDimElements = aNbNodes;
155     aDimension = 0;
156   }
157
158   // information about the mesh
159   anInfo.append(QString("Nb of element of dimension %1:<b> %2</b><br>").arg(aDimension).arg(aNbDimElements));
160   anInfo.append(QString("Nb of nodes: <b>%1</b><br><br>").arg(aNbNodes));
161
162   bool hasGroup = false;
163
164   // info about groups on nodes
165   SO->FindSubObject( Tag_NodeGroups, anObj );
166   if( anObj )
167   {
168     _PTR(ChildIterator) it = studyDS()->NewChildIterator(anObj);
169     if( it->More() )
170     {
171       anInfo.append(QString("Groups:<br><br>"));
172       hasGroup = true;
173     
174       for( ; it->More(); it->Next() )
175       {
176         _PTR(SObject) subObj = it->Value();
177         CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
178         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
179         if( !aGroup->_is_nil() )
180         {
181           anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
182           anInfo.append(QString("%1<br>").arg("on nodes"));
183           anInfo.append(QString("%1<br>").arg(aGroup->Size()));
184           // check if the group based on geometry
185           SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
186           if (!aGroupOnGeom->_is_nil())
187           {
188             GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
189             QString aShapeName = "<unknown>";
190             _PTR(SObject) aGeomObj, aRef;
191             if (subObj->FindSubObject(1, aGeomObj) &&  aGeomObj->ReferencedObject(aRef))
192               aShapeName = aRef->GetName().c_str();
193             anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
194           }
195           else
196             anInfo.append(QString("<br>"));
197         }
198       }
199     }
200
201     // info about groups on edges
202     anObj.reset();
203     SO->FindSubObject(Tag_EdgeGroups, anObj);
204     if( anObj )
205     {
206       _PTR(ChildIterator) it = studyDS()->NewChildIterator(anObj);
207       if( !hasGroup && it->More() )
208       {
209         anInfo.append(QString("Groups:<br><br>"));
210         hasGroup = true;
211       }
212       for( ; it->More(); it->Next() )
213       {
214         _PTR(SObject) subObj = it->Value();
215         CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
216         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
217         if( !aGroup->_is_nil() )
218         {
219           anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
220           anInfo.append(QString("%1<br>").arg("on edges"));
221           anInfo.append(QString("%1<br>").arg(aGroup->Size()));
222           // check if the group based on geometry
223           SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
224           if( !aGroupOnGeom->_is_nil() )
225           {
226             GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
227             QString aShapeName = "<unknown>";
228             _PTR(SObject) aGeomObj, aRef;
229             if( subObj->FindSubObject( 1, aGeomObj ) && aGeomObj->ReferencedObject( aRef ) )
230               aShapeName = aRef->GetName().c_str();
231             anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
232           }
233           else
234             anInfo.append(QString("<br>"));
235         }
236       }
237     }
238
239     // info about groups on faces
240     anObj.reset();
241     SO->FindSubObject( Tag_FaceGroups, anObj );
242     if (anObj)
243     {
244       _PTR(ChildIterator) it = studyDS()->NewChildIterator(anObj);
245       if( !hasGroup && it->More() )
246       {
247         anInfo.append(QString("Groups:<br><br>"));
248         hasGroup = true;
249       }
250       for( ; it->More(); it->Next() )
251       {
252         _PTR(SObject) subObj = it->Value();
253         CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
254         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
255         if( !aGroup->_is_nil() )
256         {
257           anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
258           anInfo.append(QString("%1<br>").arg("on faces"));
259           anInfo.append(QString("%1<br>").arg(aGroup->Size()));
260           // check if the group based on geometry
261           SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
262           if( !aGroupOnGeom->_is_nil() )
263           {
264             GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
265             QString aShapeName = "<unknown>";
266             _PTR(SObject) aGeomObj, aRef;
267             if (subObj->FindSubObject(1, aGeomObj) && aGeomObj->ReferencedObject(aRef))
268               aShapeName = aRef->GetName().c_str();
269             anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
270           }
271           else
272             anInfo.append(QString("<br>"));
273         }
274       }
275     }
276
277     // info about groups on volumes
278     anObj.reset();
279     SO->FindSubObject( Tag_VolumeGroups, anObj );
280     if( anObj )
281     {
282       _PTR(ChildIterator) it = studyDS()->NewChildIterator(anObj);
283       if( !hasGroup && it->More() )
284         anInfo.append(QString("Groups:<br>"));
285       for( ; it->More(); it->Next() )
286       {
287         _PTR(SObject) subObj = it->Value();
288         CORBA::Object_var anObject = SMESH::SObjectToObject(subObj);
289         SMESH::SMESH_GroupBase_var aGroup = SMESH::SMESH_GroupBase::_narrow(anObject);
290         if( !aGroup->_is_nil() )
291         {
292           anInfo.append(QString("-   <b>%1</b><br>").arg(aGroup->GetName()));
293           anInfo.append(QString("%1<br>").arg("on volumes"));
294           anInfo.append(QString("%1<br>").arg(aGroup->Size()));
295           // check if the group based on geometry
296           SMESH::SMESH_GroupOnGeom_var aGroupOnGeom = SMESH::SMESH_GroupOnGeom::_narrow(aGroup);
297           if( !aGroupOnGeom->_is_nil() )
298           {
299             GEOM::GEOM_Object_var aGroupMainShape = aGroupOnGeom->GetShape();
300             QString aShapeName = "<unknown>";
301             _PTR(SObject) aGeomObj, aRef;
302             if (subObj->FindSubObject(1, aGeomObj) &&  aGeomObj->ReferencedObject(aRef))
303               aShapeName = aRef->GetName().c_str();
304             anInfo.append(QString("based on <i>%1</i> geometry object<br><br>").arg(aShapeName));
305           }
306           else
307             anInfo.append(QString("<br>"));
308         }
309       }
310     }
311   }
312   myDlg->setInfo(anInfo);
313 }
314
315 //=================================================================================
316 // function : onOk
317 // purpose  :
318 //=================================================================================
319 void SMESHGUI_StandardMeshInfosOp::onOk()
320 {
321   commit();
322 }
323
324 //=================================================================================
325 // function : onSelectionChanged
326 // purpose  :
327 //=================================================================================
328 void SMESHGUI_StandardMeshInfosOp::onSelectionChanged( int )
329 {
330   fillMeshInfos();
331 }
332
333