1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MeasureGUI_WhatisDlg.cxx
25 // Author : Nicolas REJNERI
30 #include "MeasureGUI_WhatisDlg.h"
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>
38 #include <qtextedit.h>
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)
50 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_WHATIS")));
51 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
53 setCaption(tr("GEOM_WHATIS_TITLE"));
55 /***************************************************************/
56 GroupConstructors->setTitle(tr("GEOM_WHATIS"));
57 RadioButton1->setPixmap(image0);
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);
65 Layout1->addWidget(GroupC1, 1, 0);
66 /***************************************************************/
73 //=================================================================================
74 // function : ~MeasureGUI_WhatisDlg()
75 // purpose : Destroys the object and frees any allocated resources
76 //=================================================================================
77 MeasureGUI_WhatisDlg::~MeasureGUI_WhatisDlg()
79 // no need to delete child widgets, Qt does it all for us
83 //=================================================================================
86 //=================================================================================
87 void MeasureGUI_WhatisDlg::Init()
90 myEditCurrentArgument = GroupC1->LineEdit1;
92 /* signals and slots connections */
93 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
94 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
96 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
106 //=================================================================================
107 // function : SelectionIntoArgument()
108 // purpose : Called when selection as changed or other case
109 //=================================================================================
110 void MeasureGUI_WhatisDlg::SelectionIntoArgument()
112 myGeomBase->EraseSimulationShape();
113 mySimulationTopoDs.Nullify();
115 myEditCurrentArgument->setText("");
116 SelectedName = ""; /* future the name of selection */
117 GroupC1->TextEdit1->setText("");
119 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, SelectedName);
125 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
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);
135 GroupC1->LineEdit1->setText(SelectedName);
136 this->CalculateWhatis(S);
142 //=================================================================================
143 // function : SetEditCurrentArgument()
145 //=================================================================================
146 void MeasureGUI_WhatisDlg::SetEditCurrentArgument()
148 QPushButton* send = (QPushButton*)sender();
150 if(send == GroupC1->PushButton1) {
151 GroupC1->LineEdit1->setFocus();
152 myEditCurrentArgument = GroupC1->LineEdit1;
155 this->SelectionIntoArgument();
160 //=================================================================================
161 // function : LineEditReturnPressed()
163 //=================================================================================
164 void MeasureGUI_WhatisDlg::LineEditReturnPressed()
166 QLineEdit* send = (QLineEdit*)sender();
167 if(send == GroupC1->LineEdit1)
168 myEditCurrentArgument = GroupC1->LineEdit1;
172 MeasureGUI_Skeleton::LineEditReturnPressed();
177 //=================================================================================
178 // function : ActivateThisDialog()
180 //=================================================================================
181 void MeasureGUI_WhatisDlg::ActivateThisDialog()
183 MeasureGUI_Skeleton::ActivateThisDialog();
184 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
185 if(!mySimulationTopoDs.IsNull())
186 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
191 //=================================================================================
192 // function : enterEvent()
194 //=================================================================================
195 void MeasureGUI_WhatisDlg::enterEvent(QEvent* e)
197 if(GroupConstructors->isEnabled())
199 this->ActivateThisDialog();
204 //=================================================================================
205 // function : CalculateWhatis()
207 //=================================================================================
208 void MeasureGUI_WhatisDlg::CalculateWhatis(const TopoDS_Shape& S)
213 TCollection_AsciiString Astr;
214 Astr = Astr + " Number of shapes in " + strdup(SelectedName.latin1()) + " : \n";
217 int iType, nbTypes [TopAbs_SHAPE];
218 for(iType = 0; iType < TopAbs_SHAPE; ++iType)
220 nbTypes[S.ShapeType()]++;
222 TopTools_MapOfShape aMapOfShape;
224 TopTools_ListOfShape aListOfShape;
225 aListOfShape.Append(S);
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()]++;
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());
249 GroupC1->TextEdit1->setText(Astr.ToCString());
251 catch(Standard_Failure) {
252 MESSAGE("Catch intercepted in CalculateWhatis()");