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