Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/geom.git] / src / MeasureGUI / MeasureGUI_CheckShapeDlg.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_CheckShapeDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "MeasureGUI_CheckShapeDlg.h"
30
31 #include <BRepCheck_Analyzer.hxx>
32
33 #include <qtextedit.h>
34
35 #include "utilities.h"
36
37 using namespace std;
38
39 //=================================================================================
40 // class    : MeasureGUI_CheckShapeDlg()
41 // purpose  : Constructs a MeasureGUI_CheckShapeDlg which is a child of 'parent', with the 
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            TRUE to construct a modal dialog.
45 //=================================================================================
46 MeasureGUI_CheckShapeDlg::MeasureGUI_CheckShapeDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
47   :MeasureGUI_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
48 {
49   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_CHECKSHAPE")));
50   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
51
52   setCaption(tr("GEOM_CHECK_TITLE"));
53
54   /***************************************************************/
55   GroupConstructors->setTitle(tr("GEOM_CHECK_SHAPE"));
56   RadioButton1->setPixmap(image0);
57
58   GroupC1 = new MeasureGUI_1Sel1TextView_QTD(this, "GroupC1");
59   GroupC1->GroupBox1->setTitle(tr("GEOM_CHECK_INFOS"));
60   GroupC1->TextLabel1->setText(tr("GEOM_OBJECT"));
61   GroupC1->TextEdit1->setReadOnly(TRUE);
62   GroupC1->PushButton1->setPixmap(image1);
63
64   Layout1->addWidget(GroupC1, 1, 0);
65   /***************************************************************/
66
67   /* Initialisation */
68   Init();
69 }
70
71
72 //=================================================================================
73 // function : ~MeasureGUI_CheckShapeDlg()
74 // purpose  : Destroys the object and frees any allocated resources
75 //=================================================================================
76 MeasureGUI_CheckShapeDlg::~MeasureGUI_CheckShapeDlg()
77 {
78   // no need to delete child widgets, Qt does it all for us
79 }
80
81
82 //=================================================================================
83 // function : Init()
84 // purpose  :
85 //=================================================================================
86 void MeasureGUI_CheckShapeDlg::Init()
87 {
88   /* init variables */
89   myEditCurrentArgument = GroupC1->LineEdit1;
90
91    /* signals and slots connections */
92   connect(GroupC1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
93   connect(GroupC1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
94
95   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
96
97   /* displays Dialog */
98   GroupC1->show();
99   this->show();
100
101   return;
102 }
103
104
105 //=================================================================================
106 // function : SelectionIntoArgument()
107 // purpose  : Called when selection as changed or other case
108 //=================================================================================
109 void MeasureGUI_CheckShapeDlg::SelectionIntoArgument()
110 {
111   myEditCurrentArgument->setText("");
112   SelectedName = ""; /* future the name of selection */
113   GroupC1->TextEdit1->setText("");
114
115   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, SelectedName);
116   if(nbSel != 1)
117     return;
118
119   /*  nbSel == 1  */
120   TopoDS_Shape S;
121   if(!myGeomBase->GetTopoFromSelection(mySelection, S))
122     return;
123
124   if(S.IsNull())
125     return;
126  
127   myEditCurrentArgument->setText(SelectedName);
128   this->Check(S);
129
130   return;
131 }
132
133
134 //=================================================================================
135 // function : SetEditCurrentArgument()
136 // purpose  :
137 //=================================================================================
138 void MeasureGUI_CheckShapeDlg::SetEditCurrentArgument()
139 {
140   QPushButton* send = (QPushButton*)sender();
141
142   if(send == GroupC1->PushButton1) {
143     GroupC1->LineEdit1->setFocus();
144     myEditCurrentArgument = GroupC1->LineEdit1;
145   }
146
147   this->SelectionIntoArgument();
148   return;
149 }
150
151
152 //=================================================================================
153 // function : LineEditReturnPressed()
154 // purpose  :
155 //=================================================================================
156 void MeasureGUI_CheckShapeDlg::LineEditReturnPressed()
157 {
158   QLineEdit* send = (QLineEdit*)sender();
159   if(send == GroupC1->LineEdit1)
160     myEditCurrentArgument = GroupC1->LineEdit1;
161   else
162     return;
163
164   MeasureGUI_Skeleton::LineEditReturnPressed();
165   return;
166 }
167
168
169 //=================================================================================
170 // function : ActivateThisDialog()
171 // purpose  :
172 //=================================================================================
173 void MeasureGUI_CheckShapeDlg::ActivateThisDialog()
174 {
175   MeasureGUI_Skeleton::ActivateThisDialog();
176   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
177   return;
178 }
179
180
181 //=================================================================================
182 // function : enterEvent()
183 // purpose  :
184 //=================================================================================
185 void MeasureGUI_CheckShapeDlg::enterEvent(QEvent* e)
186 {
187   if(GroupConstructors->isEnabled())
188     return;
189   this->ActivateThisDialog();
190   return;
191 }
192
193
194 //=================================================================================
195 // function : Check()
196 // purpose  :
197 //=================================================================================
198 void MeasureGUI_CheckShapeDlg::Check(const TopoDS_Shape S)
199 {
200   if(S.IsNull()) 
201     return;
202     
203   try {
204     BRepCheck_Analyzer ana(S,false);
205     if(ana.IsValid()) 
206       GroupC1->TextEdit1->setText("This Shape seems to be valid.");
207     else 
208       GroupC1->TextEdit1->setText("This Shape is not valid.");
209   }
210   catch(Standard_Failure) {
211     MESSAGE("Catch intercepted in Check()");
212   }
213   return;
214 }