]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_CheckShapeDlg.cxx
Salome HOME
Fix issue 0020479: EDF 1116 GEOM: Create a group, "Add" button is inactive but "Selec...
[modules/geom.git] / src / MeasureGUI / MeasureGUI_CheckShapeDlg.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  GEOM GEOMGUI : GUI for Geometry component
23 //  File   : MeasureGUI_CheckShapeDlg.cxx
24 //  Author : Nicolas REJNERI
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "MeasureGUI_CheckShapeDlg.h"
29
30 #include "utilities.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Tools.h"
33
34 #include <qtextedit.h>
35 #include <qlineedit.h>
36 #include <qlabel.h>
37 #include <qlayout.h>
38 #include <qpushbutton.h>
39 #include <qradiobutton.h>
40 #include <qbuttongroup.h>
41 #include <qcheckbox.h>
42
43 #define TEXTEDIT_FONT_FAMILY "Courier"
44 #define TEXTEDIT_FONT_SIZE 11
45
46 MeasureGUI_1Sel1TextView1Check_QTD::MeasureGUI_1Sel1TextView1Check_QTD(QWidget* parent,
47                                                                        const char* name, WFlags fl)
48   : MeasureGUI_1Sel1TextView_QTD(parent, name, fl)
49 {
50   CheckBoxGeom = new QCheckBox(GroupBox1, "CheckBoxGeom");
51   CheckBoxGeom->setText(tr("CHECK_SHAPE_GEOMETRY"));
52   Layout1->addMultiCellWidget(CheckBoxGeom, 2, 2, 0, 2);
53
54   CheckBoxGeom->setChecked(false);
55 }
56
57 MeasureGUI_1Sel1TextView1Check_QTD::~MeasureGUI_1Sel1TextView1Check_QTD()
58 {
59   // no need to delete child widgets, Qt does it all for us
60 }
61
62 //=================================================================================
63 // class    : MeasureGUI_CheckShapeDlg()
64 // purpose  : Constructs a MeasureGUI_CheckShapeDlg which is a child of 'parent', with the
65 //            name 'name' and widget flags set to 'f'.
66 //            The dialog will by default be modeless, unless you set 'modal' to
67 //            TRUE to construct a modal dialog.
68 //=================================================================================
69 MeasureGUI_CheckShapeDlg::MeasureGUI_CheckShapeDlg( GeometryGUI* GUI, QWidget* parent )
70 : MeasureGUI_Skeleton( GUI, parent, "MeasureGUI_CheckShapeDlg" )
71 {
72   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
73     "GEOM",tr( "ICON_DLG_CHECKSHAPE" ) ) );
74   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
75     "GEOM",tr( "ICON_SELECT" ) ) );
76
77   setCaption( tr( "GEOM_CHECK_TITLE" ) );
78
79   /***************************************************************/
80
81   GroupConstructors->setTitle( tr( "GEOM_CHECK_SHAPE" ) );
82   RadioButton1->setPixmap( image0 );
83
84   myGrp = new MeasureGUI_1Sel1TextView1Check_QTD( this, "myGrp" );
85   myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
86   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
87   myGrp->TextEdit1->setReadOnly( TRUE );
88
89   QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
90   aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
91   myGrp->TextEdit1->setFont( aFont );
92   myGrp->PushButton1->setPixmap( image1 );
93   myGrp->LineEdit1->setReadOnly( true );
94
95   Layout1->addWidget( myGrp, 1, 0 );
96
97   /***************************************************************/
98
99   myHelpFileName = "using_measurement_tools_page.html#check_anchor";
100
101   /* Initialisation */
102   Init();
103 }
104
105 //=================================================================================
106 // function : ~MeasureGUI_CheckShapeDlg()
107 // purpose  : Destroys the object and frees any allocated resources
108 //=================================================================================
109 MeasureGUI_CheckShapeDlg::~MeasureGUI_CheckShapeDlg()
110 {
111 }
112
113
114 //=================================================================================
115 // function : Init()
116 // purpose  :
117 //=================================================================================
118 void MeasureGUI_CheckShapeDlg::Init()
119 {
120   mySelBtn = myGrp->PushButton1;
121   mySelEdit = myGrp->LineEdit1;
122   MeasureGUI_Skeleton::Init();
123
124   connect(myGrp->CheckBoxGeom, SIGNAL(toggled(bool)), 
125           this, SLOT(SelectionIntoArgument()));
126 }
127
128 //=================================================================================
129 // function : getParameters
130 // purpose  :
131 //=================================================================================
132 bool MeasureGUI_CheckShapeDlg::getParameters ( bool& theIsValid, QString& theMsg )
133 {
134   if ( myObj->_is_nil() )
135     return false;
136   else
137   {
138     try
139     {
140       char* aMsg;
141       bool isCheckGeometry = myGrp->CheckBoxGeom->isChecked();
142       GEOM::GEOM_IMeasureOperations_ptr aMeasureOp =
143         GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
144       if (isCheckGeometry)
145         theIsValid = aMeasureOp->CheckShapeWithGeometry(myObj, aMsg);
146       else
147         theIsValid = aMeasureOp->CheckShape(myObj, aMsg);
148       theMsg = aMsg;
149     }
150     catch( const SALOME::SALOME_Exception& e )
151     {
152       SalomeApp_Tools::QtCatchCorbaException( e );
153       return false;
154     }
155
156     return getOperation()->IsDone();
157   }
158 }
159
160
161 //=================================================================================
162 // function : processObject
163 // purpose  :
164 //=================================================================================
165 void MeasureGUI_CheckShapeDlg::processObject()
166 {
167   bool isShapeValid;
168   QString aMsg;
169   if ( !getParameters( isShapeValid, aMsg ) )
170   {
171     myGrp->TextEdit1->setText( "" );
172     return;
173   }
174
175   if (isShapeValid) {
176     myGrp->TextEdit1->setText("This Shape seems to be valid.");
177   } else {
178     QString aDescr ("This Shape is not valid.\n");
179     aDescr += aMsg;
180     myGrp->TextEdit1->setText(aDescr);
181 //    myGrp->TextEdit1->setText("This Shape is not valid.");
182   }
183 }