Salome HOME
DCQ : New Architecture
[modules/geom.git] / src / MeasureGUI / MeasureGUI_WhatisDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry 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   : MeasureGUI_WhatisDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "MeasureGUI_WhatisDlg.h"
31
32 #include <TopTools_MapOfShape.hxx>
33 #include <TCollection_AsciiString.hxx>
34 #include <TopTools_ListOfShape.hxx>
35 #include <TopTools_ListIteratorOfListOfShape.hxx>
36 #include <TopoDS_Iterator.hxx>
37
38 #include <qtextedit.h>
39
40 //=================================================================================
41 // class    : MeasureGUI_WhatisDlg()
42 // purpose  : Constructs a MeasureGUI_WhatisDlg which is a child of 'parent', with the 
43 //            name 'name' and widget flags set to 'f'.
44 //            The dialog will by default be modeless, unless you set 'modal' to
45 //            TRUE to construct a modal dialog.
46 //=================================================================================
47 MeasureGUI_WhatisDlg::MeasureGUI_WhatisDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
48   :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
49 {
50   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_WHATIS")));
51   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
52
53   setCaption(tr("GEOM_WHATIS_TITLE"));
54
55   /***************************************************************/
56   GroupConstructors->setTitle(tr("GEOM_WHATIS"));
57   RadioButton1->setPixmap(image0);
58
59   GroupC1 = new MeasureGUI_1Sel1TextView_QTD(this, "GroupC1");
60   GroupC1->GroupBox1->setTitle(tr("GEOM_WHATIS_OBJECT"));
61   GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
62   GroupC1->TextEdit1->setReadOnly(TRUE);
63   GroupC1->PushButton1->setPixmap(image1);
64
65   Layout1->addWidget(GroupC1, 1, 0);
66   /***************************************************************/
67
68   /* Initialisation */
69   Init();
70 }
71
72
73 //=================================================================================
74 // function : ~MeasureGUI_WhatisDlg()
75 // purpose  : Destroys the object and frees any allocated resources
76 //=================================================================================
77 MeasureGUI_WhatisDlg::~MeasureGUI_WhatisDlg()
78 {
79   // no need to delete child widgets, Qt does it all for us
80 }
81
82
83 //=================================================================================
84 // function : Init()
85 // purpose  :
86 //=================================================================================
87 void MeasureGUI_WhatisDlg::Init()
88 {
89   /* init variables */
90   myEditCurrentArgument = GroupC1->LineEdit1;
91
92    /* signals and slots connections */
93   connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
94   connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
95
96   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
97
98   /* displays Dialog */
99   GroupC1->show();
100   this->show();
101
102   return;
103 }
104
105
106 //=================================================================================
107 // function : SelectionIntoArgument()
108 // purpose  : Called when selection as changed or other case
109 //=================================================================================
110 void MeasureGUI_WhatisDlg::SelectionIntoArgument()
111 {
112   myGeomBase->EraseSimulationShape();
113   mySimulationTopoDs.Nullify();
114
115   myEditCurrentArgument->setText("");
116   SelectedName = ""; /* future the name of selection */
117   GroupC1->TextEdit1->setText("");
118
119   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, SelectedName);
120   if(nbSel != 1)
121     return;
122
123   /*  nbSel == 1  */
124   TopoDS_Shape S;
125   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
126     return;
127
128   if(S.IsNull())
129     return;
130
131    /* Try to display of a cone simulation shape to show direction of a linear edge only in OCC viewer */
132   if(myGeomBase->CreateArrowForLinearEdge(S, mySimulationTopoDs))
133     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
134
135   GroupC1->LineEdit1->setText(SelectedName);
136   this->CalculateWhatis(S);
137
138   return;
139 }
140
141
142 //=================================================================================
143 // function : SetEditCurrentArgument()
144 // purpose  :
145 //=================================================================================
146 void MeasureGUI_WhatisDlg::SetEditCurrentArgument()
147 {
148   QPushButton* send = (QPushButton*)sender();
149
150   if(send == GroupC1->PushButton1) {
151     GroupC1->LineEdit1->setFocus();
152     myEditCurrentArgument = GroupC1->LineEdit1;
153   }
154
155   this->SelectionIntoArgument();
156   return;
157 }
158
159
160 //=================================================================================
161 // function : LineEditReturnPressed()
162 // purpose  :
163 //=================================================================================
164 void MeasureGUI_WhatisDlg::LineEditReturnPressed()
165 {
166   QLineEdit* send = (QLineEdit*)sender();
167   if(send == GroupC1->LineEdit1)
168     myEditCurrentArgument = GroupC1->LineEdit1;
169   else
170     return;
171
172   MeasureGUI_Skeleton::LineEditReturnPressed();
173   return;
174 }
175
176
177 //=================================================================================
178 // function : ActivateThisDialog()
179 // purpose  :
180 //=================================================================================
181 void MeasureGUI_WhatisDlg::ActivateThisDialog()
182 {
183   MeasureGUI_Skeleton::ActivateThisDialog();
184   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185   if(!mySimulationTopoDs.IsNull())
186     myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
187   return;
188 }
189
190
191 //=================================================================================
192 // function : enterEvent()
193 // purpose  :
194 //=================================================================================
195 void MeasureGUI_WhatisDlg::enterEvent(QEvent* e)
196 {
197   if(GroupConstructors->isEnabled())
198     return;
199   this->ActivateThisDialog();
200   return;
201 }
202
203
204 //=================================================================================
205 // function : CalculateWhatis()
206 // purpose  :
207 //=================================================================================
208 void MeasureGUI_WhatisDlg::CalculateWhatis(const TopoDS_Shape& S)
209 {
210   if(S.IsNull()) 
211     return;
212
213   TCollection_AsciiString Astr; 
214   Astr = Astr + " Number of shapes in " + strdup(SelectedName.latin1()) + " : \n";
215
216   try {
217     int iType, nbTypes [TopAbs_SHAPE];
218     for(iType = 0; iType < TopAbs_SHAPE; ++iType)
219       nbTypes[iType] = 0;
220     nbTypes[S.ShapeType()]++;
221
222     TopTools_MapOfShape aMapOfShape;
223     aMapOfShape.Add(S);
224     TopTools_ListOfShape aListOfShape;
225     aListOfShape.Append(S);
226
227     TopTools_ListIteratorOfListOfShape itL(aListOfShape);
228     for(; itL.More(); itL.Next()) {
229       TopoDS_Iterator it(itL.Value());
230       for(; it.More(); it.Next()) {
231         TopoDS_Shape s = it.Value();
232         if(aMapOfShape.Add(s)) {
233           aListOfShape.Append(s);
234           nbTypes[s.ShapeType()]++;
235         }
236       }
237     }
238
239     Astr = Astr + " VERTEX : " + TCollection_AsciiString(nbTypes[TopAbs_VERTEX]) + "\n";
240     Astr = Astr + " EDGE : " + TCollection_AsciiString(nbTypes[TopAbs_EDGE]) + "\n";
241     Astr = Astr + " WIRE : " + TCollection_AsciiString(nbTypes[TopAbs_WIRE]) + "\n";
242     Astr = Astr + " FACE : " + TCollection_AsciiString(nbTypes[TopAbs_FACE]) + "\n";
243     Astr = Astr + " SHELL : " + TCollection_AsciiString(nbTypes[TopAbs_SHELL]) + "\n";
244     Astr = Astr + " SOLID : " + TCollection_AsciiString(nbTypes[TopAbs_SOLID]) + "\n";
245     Astr = Astr + " COMPSOLID : " + TCollection_AsciiString(nbTypes[TopAbs_COMPSOLID]) + "\n";
246     Astr = Astr + " COMPOUND : " + TCollection_AsciiString(nbTypes[TopAbs_COMPOUND]) + "\n";
247     Astr = Astr + " SHAPE : " + TCollection_AsciiString(aMapOfShape.Extent());
248
249     GroupC1->TextEdit1->setText(Astr.ToCString());
250   }
251   catch(Standard_Failure) {
252     MESSAGE("Catch intercepted in CalculateWhatis()");
253   }
254   return;
255 }