Salome HOME
Merge with version on tag OCC-V2_1_0d
[modules/geom.git] / src / MeasureGUI / MeasureGUI_BndBoxDlg.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_BndBoxDlg.cxx
25 //  Author : Nicolas REJNERI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "MeasureGUI_BndBoxDlg.h"
30 #include "MeasureGUI_1Sel6LineEdit_QTD.h"
31 #include "SALOMEGUI_QtCatchCorbaException.hxx"
32
33 #include "GEOMBase.h"
34 #include "GEOM_Displayer.h"
35
36 #include <BRepPrimAPI_MakeBox.hxx>
37
38 #include "utilities.h"
39 #include "QAD_Desktop.h"
40
41 #include <qlineedit.h>
42 #include <qlayout.h>
43 #include <qpushbutton.h>
44 #include <qradiobutton.h>
45 #include <qbuttongroup.h>
46
47 //=================================================================================
48 // class    : MeasureGUI_BndBoxDlg()
49 // purpose  : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the 
50 //            name 'name' and widget flags set to 'f'.
51 //            The dialog will by default be modeless, unless you set 'modal' to
52 //            TRUE to construct a modal dialog.
53 //=================================================================================
54 MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( QWidget* parent, SALOME_Selection* Sel )
55 : MeasureGUI_Skeleton( parent, "MeasureGUI_PropertiesDlg", Sel )
56 {
57   QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap(
58     "GEOM",tr( "ICON_DLG_BOUNDING_BOX" ) ) );
59   QPixmap image1( QAD_Desktop::getResourceManager()->loadPixmap(
60     "GEOM",tr( "ICON_SELECT" ) ) );
61
62   setCaption( tr( "GEOM_BNDBOX_TITLE" ) );
63
64   /***************************************************************/
65   
66   GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
67   RadioButton1->setPixmap( image0 );
68
69   myGrp = new MeasureGUI_1Sel6LineEdit_QTD( this, "myGrp" );
70   myGrp->GroupBox1->setTitle( tr( "GEOM_BNDBOX_OBJDIM" ) );
71   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
72   myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
73   myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
74   myGrp->TextLabel4->setText( tr( "GEOM_X" ) );
75   myGrp->TextLabel5->setText( tr( "GEOM_Y" ) );
76   myGrp->TextLabel6->setText( tr( "GEOM_Z" ) );
77   myGrp->LineEdit11->setReadOnly( TRUE );
78   myGrp->LineEdit12->setReadOnly( TRUE );
79   myGrp->LineEdit21->setReadOnly( TRUE );
80   myGrp->LineEdit22->setReadOnly( TRUE );
81   myGrp->LineEdit31->setReadOnly( TRUE );
82   myGrp->LineEdit32->setReadOnly( TRUE );
83   myGrp->PushButton1->setPixmap( image1 );
84   myGrp->LineEdit1->setReadOnly( true );
85
86   Layout1->addWidget( myGrp, 1, 0 );
87   
88   /***************************************************************/
89
90   /* Initialisation */
91   Init( Sel );
92 }
93
94
95 //=================================================================================
96 // function : ~MeasureGUI_BndBoxDlg()
97 // purpose  : Destroys the object and frees any allocated resources
98 //=================================================================================
99 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
100 {
101 }
102
103
104 //=================================================================================
105 // function : Init()
106 // purpose  :
107 //=================================================================================
108 void MeasureGUI_BndBoxDlg::Init( SALOME_Selection* Sel )
109 {
110   mySelBtn = myGrp->PushButton1;
111   mySelEdit = myGrp->LineEdit1;
112   MeasureGUI_Skeleton::Init( Sel );
113 }
114
115 //=================================================================================
116 // function : processObject
117 // purpose  :
118 //=================================================================================
119 void MeasureGUI_BndBoxDlg::processObject()
120 {
121   double aXMin, aXMax, aYMin, aYMax, aZMin, aZMax;
122
123   if ( !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
124   {
125     mySelEdit->setText( "" );
126     myGrp->LineEdit11->setText( "" );
127     myGrp->LineEdit12->setText( "" );
128     myGrp->LineEdit21->setText( "" );
129     myGrp->LineEdit22->setText( "" );
130     myGrp->LineEdit31->setText( "" );
131     myGrp->LineEdit32->setText( "" );
132   }
133   else
134   {
135     
136     myGrp->LineEdit11->setText( tr( "%1" ).arg( aXMin, 12, 'f', 6 ) );
137     myGrp->LineEdit12->setText( tr( "%1" ).arg( aXMax, 12, 'f', 6 ) );
138
139     myGrp->LineEdit21->setText( tr( "%1" ).arg( aYMin, 12, 'f', 6 ) );
140     myGrp->LineEdit22->setText( tr( "%1" ).arg( aYMax, 12, 'f', 6 ) );
141
142     myGrp->LineEdit31->setText( tr( "%1" ).arg( aZMin, 12, 'f', 6 ) );
143     myGrp->LineEdit32->setText( tr( "%1" ).arg( aZMax, 12, 'f', 6 ) );            
144   }
145 }
146
147 //=================================================================================
148 // function : getParameters
149 // purpose  :
150 //=================================================================================
151 bool MeasureGUI_BndBoxDlg::getParameters( double& theXmin, double& theXmax,
152                                           double& theYmin, double& theYmax,
153                                           double& theZmin, double& theZmax )
154 {
155   if ( myObj->_is_nil() )
156     return false;
157   else
158   {
159     try
160     {
161       GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetBoundingBox(
162         myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax );
163     }
164     catch( const SALOME::SALOME_Exception& e )
165     {
166       QtCatchCorbaException( e );
167       return false;
168     }
169
170     return getOperation()->IsDone();
171   }
172 }
173
174 //=================================================================================
175 // function : buildPrs
176 // purpose  :
177 //=================================================================================
178 SALOME_Prs* MeasureGUI_BndBoxDlg::buildPrs()
179 {
180   double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
181
182   if ( myObj->_is_nil() || !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
183     return 0;
184
185   TopoDS_Shape aShape = BRepPrimAPI_MakeBox( gp_Pnt( aXMin, aYMin, aZMin ),
186                                              gp_Pnt( aXMax, aYMax, aZMax ) ).Shape();
187        
188   return !aShape.IsNull() ? getDisplayer()->BuildPrs( aShape ) : 0;
189
190 }
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209