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