]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_BndBoxDlg.cxx
Salome HOME
Mantis issue 0020706: EDF 1263 GEOM: Suppress faces does notremove faces and adds...
[modules/geom.git] / src / MeasureGUI / MeasureGUI_BndBoxDlg.cxx
1 //  Copyright (C) 2007-2008  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
33 #include <GEOM_Function.hxx>
34 #include <GEOM_Object.hxx>
35
36 #include <BRepPrimAPI_MakeBox.hxx>
37 #include <BRepAdaptor_Surface.hxx>
38 #include <BRep_Tool.hxx>
39 #include <BRep_TFace.hxx>
40 #include <TopoDS.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <TopExp_Explorer.hxx>
43
44 #include <SUIT_Session.h>
45 #include <SUIT_ResourceMgr.h>
46 #include <SalomeApp_Tools.h>
47
48 // #include <qlineedit.h>
49 // #include <qlabel.h>
50 // #include <qlayout.h>
51 // #include <qpushbutton.h>
52 // #include <qradiobutton.h>
53 // #include <qbuttongroup.h>
54
55 //=================================================================================
56 // class    : MeasureGUI_BndBoxDlg()
57 // purpose  : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the 
58 //            name 'name' and widget flags set to 'f'.
59 //            The dialog will by default be modeless, unless you set 'modal' to
60 //            true to construct a modal dialog.
61 //=================================================================================
62 MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( GeometryGUI* GUI, QWidget* parent )
63   : MeasureGUI_Skeleton( GUI, parent )
64 {
65   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
66     "GEOM", tr( "ICON_DLG_BOUNDING_BOX" ) ) );
67   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
68     "GEOM", tr( "ICON_SELECT" ) ) );
69
70   setWindowTitle( tr( "GEOM_BNDBOX_TITLE" ) );
71
72   /***************************************************************/
73   
74   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
75   mainFrame()->RadioButton1->setIcon( image0 );
76
77   myGrp = new MeasureGUI_1Sel6LineEdit( centralWidget() );
78   myGrp->GroupBox1->setTitle( tr( "GEOM_BNDBOX_OBJDIM" ) );
79   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
80   myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
81   myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
82   myGrp->TextLabel4->setText( tr( "GEOM_X" ) );
83   myGrp->TextLabel5->setText( tr( "GEOM_Y" ) );
84   myGrp->TextLabel6->setText( tr( "GEOM_Z" ) );
85   myGrp->LineEdit11->setReadOnly( true );
86   myGrp->LineEdit12->setReadOnly( true );
87   myGrp->LineEdit21->setReadOnly( true );
88   myGrp->LineEdit22->setReadOnly( true );
89   myGrp->LineEdit31->setReadOnly( true );
90   myGrp->LineEdit32->setReadOnly( true );
91   myGrp->PushButton1->setIcon( image1 );
92   myGrp->LineEdit1->setReadOnly( true );
93
94   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
95   layout->setMargin( 0 ); layout->setSpacing( 6 );
96   layout->addWidget( myGrp );
97   
98   /***************************************************************/
99
100   myHelpFileName = "using_measurement_tools_page.html#bounding_box_anchor";
101
102   /* Initialisation */
103   Init();
104 }
105
106
107 //=================================================================================
108 // function : ~MeasureGUI_BndBoxDlg()
109 // purpose  : Destroys the object and frees any allocated resources
110 //=================================================================================
111 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
112 {
113 }
114
115
116 //=================================================================================
117 // function : Init()
118 // purpose  :
119 //=================================================================================
120 void MeasureGUI_BndBoxDlg::Init()
121 {
122   mySelBtn = myGrp->PushButton1;
123   mySelEdit = myGrp->LineEdit1;
124   MeasureGUI_Skeleton::Init();
125 }
126
127 //=================================================================================
128 // function : processObject
129 // purpose  :
130 //=================================================================================
131 void MeasureGUI_BndBoxDlg::processObject()
132 {
133   double aXMin, aXMax, aYMin, aYMax, aZMin, aZMax;
134
135   if ( !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) ) {
136     mySelEdit->setText( "" );
137     myGrp->LineEdit11->setText( "" );
138     myGrp->LineEdit12->setText( "" );
139     myGrp->LineEdit21->setText( "" );
140     myGrp->LineEdit22->setText( "" );
141     myGrp->LineEdit31->setText( "" );
142     myGrp->LineEdit32->setText( "" );
143   }
144   else {
145     myGrp->LineEdit11->setText( tr( "%1" ).arg( aXMin, 12, 'f', 6 ) );
146     myGrp->LineEdit12->setText( tr( "%1" ).arg( aXMax, 12, 'f', 6 ) );
147
148     myGrp->LineEdit21->setText( tr( "%1" ).arg( aYMin, 12, 'f', 6 ) );
149     myGrp->LineEdit22->setText( tr( "%1" ).arg( aYMax, 12, 'f', 6 ) );
150
151     myGrp->LineEdit31->setText( tr( "%1" ).arg( aZMin, 12, 'f', 6 ) );
152     myGrp->LineEdit32->setText( tr( "%1" ).arg( aZMax, 12, 'f', 6 ) );            
153   }
154 }
155
156 //=================================================================================
157 // function : getParameters
158 // purpose  :
159 //=================================================================================
160 bool MeasureGUI_BndBoxDlg::getParameters( double& theXmin, double& theXmax,
161                                           double& theYmin, double& theYmax,
162                                           double& theZmin, double& theZmax )
163 {
164   if ( myObj->_is_nil() )
165     return false;
166   else {
167     GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
168     try {
169       Handle(Poly_Triangulation) Trtn = 0; 
170
171       GEOM::GEOM_Gen_var aGeomGen = GeometryGUI::GetGeomGen();
172       if ( CORBA::is_nil(aGeomGen) )
173         return false;
174
175       char* IOR = GEOMBase::GetIORFromObject( myObj );
176       GEOM::GEOM_Object_var anObject = aGeomGen->GetIORFromString(IOR);
177       if ( CORBA::is_nil(anObject) )
178         return false;
179
180       TopoDS_Shape aShape;
181       GEOMBase::GetShape(anObject, aShape, TopAbs_SHAPE);
182       if ( aShape.IsNull() )
183         return false;
184       
185       TopLoc_Location l;
186       Handle(Poly_Triangulation) T;
187       TopExp_Explorer ex;
188       for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
189         const TopoDS_Face& F = TopoDS::Face(ex.Current());
190         BRepAdaptor_Surface surf(F);
191         if (surf.GetType() == GeomAbs_Sphere) {
192           T = BRep_Tool::Triangulation(F, l);
193           if (!T.IsNull()) {
194             Handle(Poly_Triangulation) NullTrtn = 0;
195             (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(NullTrtn);
196             Trtn = T;
197             break;
198           }
199         }
200         else
201           break;
202       }
203       
204       anOper->GetBoundingBox( myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax );
205       
206       if (!Trtn.IsNull()) {
207         TopLoc_Location l;
208         Handle(Poly_Triangulation) T;
209         TopExp_Explorer ex;
210         for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
211           const TopoDS_Face& F = TopoDS::Face(ex.Current());
212           (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(Trtn);
213           break;
214         }
215       }
216       
217     }
218     catch( const SALOME::SALOME_Exception& e ) {
219       SalomeApp_Tools::QtCatchCorbaException( e );
220       return false;
221     }
222
223     return anOper->IsDone();
224   }
225 }
226
227 //=================================================================================
228 // function : buildPrs
229 // purpose  :
230 //=================================================================================
231 SALOME_Prs* MeasureGUI_BndBoxDlg::buildPrs()
232 {
233   double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
234
235   if ( myObj->_is_nil() || !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
236     return 0;
237
238   TopoDS_Shape aShape = BRepPrimAPI_MakeBox( gp_Pnt( aXMin, aYMin, aZMin ),
239                                              gp_Pnt( aXMax, aYMax, aZMax ) ).Shape();
240        
241   return !aShape.IsNull() ? getDisplayer()->BuildPrs( aShape ) : 0;
242
243 }