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
29 #include "MeasureGUI_WhatisDlg.h"
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>
37 #include <qtextedit.h>
39 #include <BRep_Tool.hxx>
41 #include "utilities.h"
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)
55 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_WHATIS")));
56 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_WHATIS_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_WHATIS"));
62 RadioButton1->setPixmap(image0);
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);
70 Layout1->addWidget(GroupC1, 1, 0);
71 /***************************************************************/
78 //=================================================================================
79 // function : ~MeasureGUI_WhatisDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 MeasureGUI_WhatisDlg::~MeasureGUI_WhatisDlg()
84 // no need to delete child widgets, Qt does it all for us
88 //=================================================================================
91 //=================================================================================
92 void MeasureGUI_WhatisDlg::Init()
95 myEditCurrentArgument = GroupC1->LineEdit1;
97 /* signals and slots connections */
98 connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
99 connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
101 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
103 /* displays Dialog */
111 //=================================================================================
112 // function : SelectionIntoArgument()
113 // purpose : Called when selection as changed or other case
114 //=================================================================================
115 void MeasureGUI_WhatisDlg::SelectionIntoArgument()
117 myGeomBase->EraseSimulationShape();
118 mySimulationTopoDs.Nullify();
120 myEditCurrentArgument->setText("");
121 SelectedName = ""; /* future the name of selection */
122 GroupC1->TextEdit1->setText("");
124 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, SelectedName);
130 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
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);
140 GroupC1->LineEdit1->setText(SelectedName);
141 this->CalculateWhatis(S);
147 //=================================================================================
148 // function : SetEditCurrentArgument()
150 //=================================================================================
151 void MeasureGUI_WhatisDlg::SetEditCurrentArgument()
153 QPushButton* send = (QPushButton*)sender();
155 if(send == GroupC1->PushButton1) {
156 GroupC1->LineEdit1->setFocus();
157 myEditCurrentArgument = GroupC1->LineEdit1;
160 this->SelectionIntoArgument();
165 //=================================================================================
166 // function : LineEditReturnPressed()
168 //=================================================================================
169 void MeasureGUI_WhatisDlg::LineEditReturnPressed()
171 QLineEdit* send = (QLineEdit*)sender();
172 if(send == GroupC1->LineEdit1)
173 myEditCurrentArgument = GroupC1->LineEdit1;
177 MeasureGUI_Skeleton::LineEditReturnPressed();
182 //=================================================================================
183 // function : ActivateThisDialog()
185 //=================================================================================
186 void MeasureGUI_WhatisDlg::ActivateThisDialog()
188 MeasureGUI_Skeleton::ActivateThisDialog();
189 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
190 if(!mySimulationTopoDs.IsNull())
191 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
196 //=================================================================================
197 // function : enterEvent()
199 //=================================================================================
200 void MeasureGUI_WhatisDlg::enterEvent(QEvent* e)
202 if(GroupConstructors->isEnabled())
204 this->ActivateThisDialog();
209 //=================================================================================
210 // function : CalculateWhatis()
212 //=================================================================================
213 void MeasureGUI_WhatisDlg::CalculateWhatis(const TopoDS_Shape& S)
218 TCollection_AsciiString Astr;
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";
226 Astr = Astr + " Number of shapes in " + CORBA::string_dup(SelectedName.latin1()) + " : \n";
229 int iType, nbTypes [TopAbs_SHAPE];
230 for(iType = 0; iType < TopAbs_SHAPE; ++iType)
232 nbTypes[S.ShapeType()]++;
234 TopTools_MapOfShape aMapOfShape;
236 TopTools_ListOfShape aListOfShape;
237 aListOfShape.Append(S);
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()]++;
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());
261 GroupC1->TextEdit1->setText(Astr.ToCString());
263 catch(Standard_Failure) {
264 MESSAGE("Catch intercepted in CalculateWhatis()");