Salome HOME
Merge from V6_main (04/10/2012)
[modules/geom.git] / src / MeasureGUI / MeasureGUI_BndBoxDlg.cxx
1 // Copyright (C) 2007-2012  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_BndBoxDlg.cxx
24 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
25
26 #include "MeasureGUI_BndBoxDlg.h"
27 #include "MeasureGUI_Widgets.h"
28
29 #include "GeometryGUI.h"
30
31 #include <GEOMBase.h>
32 #include <DlgRef.h>
33
34 #include <BRepPrimAPI_MakeBox.hxx>
35
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
38
39 //=================================================================================
40 // class    : MeasureGUI_BndBoxDlg()
41 // purpose  : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the
42 //            name 'name' and widget flags set to 'f'.
43 //            The dialog will by default be modeless, unless you set 'modal' to
44 //            true to construct a modal dialog.
45 //=================================================================================
46 MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg (GeometryGUI* GUI, QWidget* parent)
47   : MeasureGUI_Skeleton(GUI, parent)
48 {
49   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
50     "GEOM", tr( "ICON_DLG_BOUNDING_BOX" ) ) );
51   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
52     "GEOM", tr( "ICON_SELECT" ) ) );
53
54   setWindowTitle( tr( "GEOM_BNDBOX_TITLE" ) );
55
56   /***************************************************************/
57
58   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
59   mainFrame()->RadioButton1->setIcon( image0 );
60
61   myGrp = new MeasureGUI_1Sel6LineEdit( centralWidget() );
62   myGrp->GroupBox1->setTitle( tr( "GEOM_BNDBOX_OBJDIM" ) );
63   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
64   myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
65   myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
66   myGrp->TextLabel4->setText( tr( "GEOM_X" ) );
67   myGrp->TextLabel5->setText( tr( "GEOM_Y" ) );
68   myGrp->TextLabel6->setText( tr( "GEOM_Z" ) );
69   myGrp->LineEdit11->setReadOnly( true );
70   myGrp->LineEdit12->setReadOnly( true );
71   myGrp->LineEdit21->setReadOnly( true );
72   myGrp->LineEdit22->setReadOnly( true );
73   myGrp->LineEdit31->setReadOnly( true );
74   myGrp->LineEdit32->setReadOnly( true );
75   myGrp->LineEdit11->setMinimumWidth(120);
76   myGrp->LineEdit12->setMinimumWidth(120);
77   myGrp->LineEdit21->setMinimumWidth(120);
78   myGrp->LineEdit22->setMinimumWidth(120);
79   myGrp->LineEdit31->setMinimumWidth(120);
80   myGrp->LineEdit32->setMinimumWidth(120);
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 = "using_measurement_tools_page.html#bounding_box_anchor";
91
92   /* Initialisation */
93   Init();
94 }
95
96 //=================================================================================
97 // function : ~MeasureGUI_BndBoxDlg()
98 // purpose  : Destroys the object and frees any allocated resources
99 //=================================================================================
100 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
101 {
102 }
103
104 //=================================================================================
105 // function : Init()
106 // purpose  :
107 //=================================================================================
108 void MeasureGUI_BndBoxDlg::Init()
109 {
110   mySelBtn = myGrp->PushButton1;
111   mySelEdit = myGrp->LineEdit1;
112   MeasureGUI_Skeleton::Init();
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     mySelEdit->setText("");
125     myGrp->LineEdit11->setText("");
126     myGrp->LineEdit12->setText("");
127     myGrp->LineEdit21->setText("");
128     myGrp->LineEdit22->setText("");
129     myGrp->LineEdit31->setText("");
130     myGrp->LineEdit32->setText("");
131   }
132   else {
133     SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
134     int aPrecision = resMgr->integerValue( "Geometry", "length_precision", 6 );
135
136     myGrp->LineEdit11->setText( DlgRef::PrintDoubleValue( aXMin, aPrecision ) );
137     myGrp->LineEdit12->setText( DlgRef::PrintDoubleValue( aXMax, aPrecision ) );
138
139     myGrp->LineEdit21->setText( DlgRef::PrintDoubleValue( aYMin, aPrecision ) );
140     myGrp->LineEdit22->setText( DlgRef::PrintDoubleValue( aYMax, aPrecision ) );
141
142     myGrp->LineEdit31->setText( DlgRef::PrintDoubleValue( aZMin, aPrecision ) );
143     myGrp->LineEdit32->setText( DlgRef::PrintDoubleValue( aZMax, aPrecision ) );
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
158   GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow(getOperation());
159   anOper->GetBoundingBox(myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax);
160
161   return anOper->IsDone();
162 }
163
164 //=================================================================================
165 // function : buildPrs
166 // purpose  :
167 //=================================================================================
168 SALOME_Prs* MeasureGUI_BndBoxDlg::buildPrs()
169 {
170   double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
171
172   if (!getParameters(aXMin, aXMax, aYMin, aYMax, aZMin, aZMax))
173     return 0;
174
175   TopoDS_Shape aShape = BRepPrimAPI_MakeBox(gp_Pnt(aXMin, aYMin, aZMin),
176                                             gp_Pnt(aXMax, aYMax, aZMax)).Shape();
177
178   return !aShape.IsNull() ? getDisplayer()->BuildPrs(aShape) : 0;
179 }