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