1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_BndBoxDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "MeasureGUI_BndBoxDlg.h"
28 #include "MeasureGUI_Widgets.h"
30 #include "GeometryGUI.h"
34 #include <GEOM_Function.hxx>
35 #include <GEOM_Object.hxx>
37 #include <BRepPrimAPI_MakeBox.hxx>
38 #include <BRepAdaptor_Surface.hxx>
39 #include <BRep_Tool.hxx>
40 #include <BRep_TFace.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopExp_Explorer.hxx>
45 #include <SUIT_Session.h>
46 #include <SUIT_ResourceMgr.h>
47 #include <SalomeApp_Tools.h>
49 // #include <qlineedit.h>
50 // #include <qlabel.h>
51 // #include <qlayout.h>
52 // #include <qpushbutton.h>
53 // #include <qradiobutton.h>
54 // #include <qbuttongroup.h>
56 //=================================================================================
57 // class : MeasureGUI_BndBoxDlg()
58 // purpose : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the
59 // name 'name' and widget flags set to 'f'.
60 // The dialog will by default be modeless, unless you set 'modal' to
61 // true to construct a modal dialog.
62 //=================================================================================
63 MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( GeometryGUI* GUI, QWidget* parent )
64 : MeasureGUI_Skeleton( GUI, parent )
66 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
67 "GEOM", tr( "ICON_DLG_BOUNDING_BOX" ) ) );
68 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
69 "GEOM", tr( "ICON_SELECT" ) ) );
71 setWindowTitle( tr( "GEOM_BNDBOX_TITLE" ) );
73 /***************************************************************/
75 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
76 mainFrame()->RadioButton1->setIcon( image0 );
78 myGrp = new MeasureGUI_1Sel6LineEdit( centralWidget() );
79 myGrp->GroupBox1->setTitle( tr( "GEOM_BNDBOX_OBJDIM" ) );
80 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
81 myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
82 myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
83 myGrp->TextLabel4->setText( tr( "GEOM_X" ) );
84 myGrp->TextLabel5->setText( tr( "GEOM_Y" ) );
85 myGrp->TextLabel6->setText( tr( "GEOM_Z" ) );
86 myGrp->LineEdit11->setReadOnly( true );
87 myGrp->LineEdit12->setReadOnly( true );
88 myGrp->LineEdit21->setReadOnly( true );
89 myGrp->LineEdit22->setReadOnly( true );
90 myGrp->LineEdit31->setReadOnly( true );
91 myGrp->LineEdit32->setReadOnly( true );
92 myGrp->PushButton1->setIcon( image1 );
93 myGrp->LineEdit1->setReadOnly( true );
95 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
96 layout->setMargin( 0 ); layout->setSpacing( 6 );
97 layout->addWidget( myGrp );
99 /***************************************************************/
101 myHelpFileName = "using_measurement_tools_page.html#bounding_box_anchor";
108 //=================================================================================
109 // function : ~MeasureGUI_BndBoxDlg()
110 // purpose : Destroys the object and frees any allocated resources
111 //=================================================================================
112 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
117 //=================================================================================
120 //=================================================================================
121 void MeasureGUI_BndBoxDlg::Init()
123 mySelBtn = myGrp->PushButton1;
124 mySelEdit = myGrp->LineEdit1;
125 MeasureGUI_Skeleton::Init();
128 //=================================================================================
129 // function : processObject
131 //=================================================================================
132 void MeasureGUI_BndBoxDlg::processObject()
134 double aXMin, aXMax, aYMin, aYMax, aZMin, aZMax;
136 if ( !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) ) {
137 mySelEdit->setText( "" );
138 myGrp->LineEdit11->setText( "" );
139 myGrp->LineEdit12->setText( "" );
140 myGrp->LineEdit21->setText( "" );
141 myGrp->LineEdit22->setText( "" );
142 myGrp->LineEdit31->setText( "" );
143 myGrp->LineEdit32->setText( "" );
146 myGrp->LineEdit11->setText( tr( "%1" ).arg( aXMin, 12, 'f', 6 ) );
147 myGrp->LineEdit12->setText( tr( "%1" ).arg( aXMax, 12, 'f', 6 ) );
149 myGrp->LineEdit21->setText( tr( "%1" ).arg( aYMin, 12, 'f', 6 ) );
150 myGrp->LineEdit22->setText( tr( "%1" ).arg( aYMax, 12, 'f', 6 ) );
152 myGrp->LineEdit31->setText( tr( "%1" ).arg( aZMin, 12, 'f', 6 ) );
153 myGrp->LineEdit32->setText( tr( "%1" ).arg( aZMax, 12, 'f', 6 ) );
157 //=================================================================================
158 // function : getParameters
160 //=================================================================================
161 bool MeasureGUI_BndBoxDlg::getParameters( double& theXmin, double& theXmax,
162 double& theYmin, double& theYmax,
163 double& theZmin, double& theZmax )
165 if ( myObj->_is_nil() )
168 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
170 Handle(Poly_Triangulation) Trtn = 0;
172 GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
173 if ( CORBA::is_nil(aGeomGen) )
176 char* IOR = GEOMBase::GetIORFromObject( myObj );
177 GEOM::GEOM_Object_var anObject = aGeomGen->GetIORFromString(IOR);
178 if ( CORBA::is_nil(anObject) )
182 GEOMBase::GetShape(anObject, aShape, TopAbs_SHAPE);
183 if ( aShape.IsNull() )
187 Handle(Poly_Triangulation) T;
189 for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
190 const TopoDS_Face& F = TopoDS::Face(ex.Current());
191 BRepAdaptor_Surface surf(F);
192 if (surf.GetType() == GeomAbs_Sphere) {
193 T = BRep_Tool::Triangulation(F, l);
195 Handle(Poly_Triangulation) NullTrtn = 0;
196 (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(NullTrtn);
205 anOper->GetBoundingBox( myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax );
207 if (!Trtn.IsNull()) {
209 Handle(Poly_Triangulation) T;
211 for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
212 const TopoDS_Face& F = TopoDS::Face(ex.Current());
213 (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(Trtn);
219 catch( const SALOME::SALOME_Exception& e ) {
220 SalomeApp_Tools::QtCatchCorbaException( e );
224 return anOper->IsDone();
228 //=================================================================================
229 // function : buildPrs
231 //=================================================================================
232 SALOME_Prs* MeasureGUI_BndBoxDlg::buildPrs()
234 double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
236 if ( myObj->_is_nil() || !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
239 TopoDS_Shape aShape = BRepPrimAPI_MakeBox( gp_Pnt( aXMin, aYMin, aZMin ),
240 gp_Pnt( aXMax, aYMax, aZMax ) ).Shape();
242 return !aShape.IsNull() ? getDisplayer()->BuildPrs( aShape ) : 0;