]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_BndBoxDlg.cxx
Salome HOME
Bug 0020043: EDF 865 GEOM: Object is non valid after translation. Fix object after...
[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 <GEOM_Function.hxx>
36 #include <GEOM_Object.hxx>
37
38 #include <BRepPrimAPI_MakeBox.hxx>
39 #include <BRepAdaptor_Surface.hxx>
40 #include <BRep_Tool.hxx>
41 #include <BRep_TFace.hxx>
42 #include <TopoDS.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TopExp_Explorer.hxx>
45
46 #include "utilities.h"
47 #include "SUIT_Session.h"
48 #include "SalomeApp_Tools.h"
49
50 #include <qlineedit.h>
51 #include <qlabel.h>
52 #include <qlayout.h>
53 #include <qpushbutton.h>
54 #include <qradiobutton.h>
55 #include <qbuttongroup.h>
56
57 //=================================================================================
58 // class    : MeasureGUI_BndBoxDlg()
59 // purpose  : Constructs a MeasureGUI_BndBoxDlg which is a child of 'parent', with the 
60 //            name 'name' and widget flags set to 'f'.
61 //            The dialog will by default be modeless, unless you set 'modal' to
62 //            TRUE to construct a modal dialog.
63 //=================================================================================
64 MeasureGUI_BndBoxDlg::MeasureGUI_BndBoxDlg( GeometryGUI* GUI, QWidget* parent )
65 : MeasureGUI_Skeleton( GUI, parent, "MeasureGUI_PropertiesDlg" )
66 {
67   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
68     "GEOM",tr( "ICON_DLG_BOUNDING_BOX" ) ) );
69   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
70     "GEOM",tr( "ICON_SELECT" ) ) );
71
72   setCaption( tr( "GEOM_BNDBOX_TITLE" ) );
73
74   /***************************************************************/
75   
76   GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
77   RadioButton1->setPixmap( image0 );
78
79   myGrp = new MeasureGUI_1Sel6LineEdit_QTD( this, "myGrp" );
80   myGrp->GroupBox1->setTitle( tr( "GEOM_BNDBOX_OBJDIM" ) );
81   myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
82   myGrp->TextLabel2->setText( tr( "GEOM_MIN" ) );
83   myGrp->TextLabel3->setText( tr( "GEOM_MAX" ) );
84   myGrp->TextLabel4->setText( tr( "GEOM_X" ) );
85   myGrp->TextLabel5->setText( tr( "GEOM_Y" ) );
86   myGrp->TextLabel6->setText( tr( "GEOM_Z" ) );
87   myGrp->LineEdit11->setReadOnly( TRUE );
88   myGrp->LineEdit12->setReadOnly( TRUE );
89   myGrp->LineEdit21->setReadOnly( TRUE );
90   myGrp->LineEdit22->setReadOnly( TRUE );
91   myGrp->LineEdit31->setReadOnly( TRUE );
92   myGrp->LineEdit32->setReadOnly( TRUE );
93   myGrp->PushButton1->setPixmap( image1 );
94   myGrp->LineEdit1->setReadOnly( true );
95
96   Layout1->addWidget( myGrp, 1, 0 );
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   {
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( "" );
144   }
145   else
146   {
147     
148     myGrp->LineEdit11->setText( tr( "%1" ).arg( aXMin, 12, 'f', 6 ) );
149     myGrp->LineEdit12->setText( tr( "%1" ).arg( aXMax, 12, 'f', 6 ) );
150
151     myGrp->LineEdit21->setText( tr( "%1" ).arg( aYMin, 12, 'f', 6 ) );
152     myGrp->LineEdit22->setText( tr( "%1" ).arg( aYMax, 12, 'f', 6 ) );
153
154     myGrp->LineEdit31->setText( tr( "%1" ).arg( aZMin, 12, 'f', 6 ) );
155     myGrp->LineEdit32->setText( tr( "%1" ).arg( aZMax, 12, 'f', 6 ) );            
156   }
157 }
158
159 //=================================================================================
160 // function : getParameters
161 // purpose  :
162 //=================================================================================
163 bool MeasureGUI_BndBoxDlg::getParameters( double& theXmin, double& theXmax,
164                                           double& theYmin, double& theYmax,
165                                           double& theZmin, double& theZmax )
166 {
167   if ( myObj->_is_nil() )
168     return false;
169   else
170   {
171     try
172     {
173       Handle(Poly_Triangulation) Trtn = 0; 
174
175       Handle(GEOM_Object) anObject = GEOM_Engine::GetEngine()->GetObject(myObj->GetStudyID(), myObj->GetEntry());
176       if (!anObject.IsNull())
177       {
178         Handle(GEOM_Function) aRefShape = anObject->GetLastFunction();
179         if (!aRefShape.IsNull())
180         {
181           TopoDS_Shape aShape = aRefShape->GetValue();
182           if (!aShape.IsNull())
183           {
184             TopLoc_Location l;
185             Handle(Poly_Triangulation) T;
186             TopExp_Explorer ex;
187             for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
188               const TopoDS_Face& F = TopoDS::Face(ex.Current());
189               
190               BRepAdaptor_Surface surf(F);
191               if (surf.GetType() == GeomAbs_Sphere)
192               {
193                 T = BRep_Tool::Triangulation(F, l);
194                 if (!T.IsNull()) {
195                   Handle(Poly_Triangulation) NullTrtn = 0;
196                   (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(NullTrtn);
197                   Trtn = T;
198                   break;
199                 }
200               }
201               else
202                 break;
203             }
204           }
205         }
206       }
207
208       GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetBoundingBox(
209         myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax );
210
211       if (!Trtn.IsNull())
212       {
213         Handle(GEOM_Function) aRefShape = anObject->GetLastFunction();
214         if (!aRefShape.IsNull())
215         {
216           TopoDS_Shape aShape = aRefShape->GetValue();
217           if (!aShape.IsNull())
218           {
219             TopLoc_Location l;
220             Handle(Poly_Triangulation) T;
221             TopExp_Explorer ex;
222             for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
223               const TopoDS_Face& F = TopoDS::Face(ex.Current());
224               (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(Trtn);
225               break;
226             }
227           }
228         }
229       }
230
231     }
232     catch( const SALOME::SALOME_Exception& e )
233     {
234       SalomeApp_Tools::QtCatchCorbaException( e );
235       return false;
236     }
237
238     return getOperation()->IsDone();
239   }
240 }
241
242 //=================================================================================
243 // function : buildPrs
244 // purpose  :
245 //=================================================================================
246 SALOME_Prs* MeasureGUI_BndBoxDlg::buildPrs()
247 {
248   double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
249
250   if ( myObj->_is_nil() || !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
251     return 0;
252
253   TopoDS_Shape aShape = BRepPrimAPI_MakeBox( gp_Pnt( aXMin, aYMin, aZMin ),
254                                              gp_Pnt( aXMax, aYMax, aZMax ) ).Shape();
255        
256   return !aShape.IsNull() ? getDisplayer()->BuildPrs( aShape ) : 0;
257
258 }