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