]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_BndBoxDlg.cxx
Salome HOME
Update for 19962 issue: MakePipeBiNormalAlongAxis implementation.
[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
25 //  Module : GEOM
26 //  $Header$
27 //
28 #include "MeasureGUI_BndBoxDlg.h"
29 #include "MeasureGUI_1Sel6LineEdit_QTD.h"
30
31 #include "GEOMBase.h"
32 #include "GEOM_Displayer.h"
33
34 #include <GEOM_Function.hxx>
35 #include <GEOM_Object.hxx>
36
37 #include <BRepPrimAPI_MakeBox.hxx>
38 #include <BRepAdaptor_Surface.hxx>
39 #include <BRep_Tool.hxx>
40 #include <BRep_TFace.hxx>
41 #include <TopoDS.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopExp_Explorer.hxx>
44
45 #include "utilities.h"
46 #include "SUIT_Session.h"
47 #include "SalomeApp_Tools.h"
48
49 #include <qlineedit.h>
50 #include <qlabel.h>
51 #include <qlayout.h>
52 #include <qpushbutton.h>
53 #include <qradiobutton.h>
54 #include <qbuttongroup.h>
55
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, "MeasureGUI_PropertiesDlg" )
65 {
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" ) ) );
70
71   setCaption( tr( "GEOM_BNDBOX_TITLE" ) );
72
73   /***************************************************************/
74   
75   GroupConstructors->setTitle( tr( "GEOM_BNDBOX" ) );
76   RadioButton1->setPixmap( image0 );
77
78   myGrp = new MeasureGUI_1Sel6LineEdit_QTD( this, "myGrp" );
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->setPixmap( image1 );
93   myGrp->LineEdit1->setReadOnly( true );
94
95   Layout1->addWidget( myGrp, 1, 0 );
96   
97   /***************************************************************/
98
99   myHelpFileName = "using_measurement_tools_page.html#bounding_box_anchor";
100
101   /* Initialisation */
102   Init();
103 }
104
105
106 //=================================================================================
107 // function : ~MeasureGUI_BndBoxDlg()
108 // purpose  : Destroys the object and frees any allocated resources
109 //=================================================================================
110 MeasureGUI_BndBoxDlg::~MeasureGUI_BndBoxDlg()
111 {
112 }
113
114
115 //=================================================================================
116 // function : Init()
117 // purpose  :
118 //=================================================================================
119 void MeasureGUI_BndBoxDlg::Init()
120 {
121   mySelBtn = myGrp->PushButton1;
122   mySelEdit = myGrp->LineEdit1;
123   MeasureGUI_Skeleton::Init();
124 }
125
126 //=================================================================================
127 // function : processObject
128 // purpose  :
129 //=================================================================================
130 void MeasureGUI_BndBoxDlg::processObject()
131 {
132   double aXMin, aXMax, aYMin, aYMax, aZMin, aZMax;
133
134   if ( !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
135   {
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   {
146     
147     myGrp->LineEdit11->setText( tr( "%1" ).arg( aXMin, 12, 'f', 6 ) );
148     myGrp->LineEdit12->setText( tr( "%1" ).arg( aXMax, 12, 'f', 6 ) );
149
150     myGrp->LineEdit21->setText( tr( "%1" ).arg( aYMin, 12, 'f', 6 ) );
151     myGrp->LineEdit22->setText( tr( "%1" ).arg( aYMax, 12, 'f', 6 ) );
152
153     myGrp->LineEdit31->setText( tr( "%1" ).arg( aZMin, 12, 'f', 6 ) );
154     myGrp->LineEdit32->setText( tr( "%1" ).arg( aZMax, 12, 'f', 6 ) );            
155   }
156 }
157
158 //=================================================================================
159 // function : getParameters
160 // purpose  :
161 //=================================================================================
162 bool MeasureGUI_BndBoxDlg::getParameters( double& theXmin, double& theXmax,
163                                           double& theYmin, double& theYmax,
164                                           double& theZmin, double& theZmax )
165 {
166   if ( myObj->_is_nil() )
167     return false;
168   else
169   {
170     try
171     {
172       Handle(Poly_Triangulation) Trtn = 0; 
173
174       Handle(GEOM_Object) anObject = GEOM_Engine::GetEngine()->GetObject(myObj->GetStudyID(), myObj->GetEntry());
175       if (!anObject.IsNull())
176       {
177         Handle(GEOM_Function) aRefShape = anObject->GetLastFunction();
178         if (!aRefShape.IsNull())
179         {
180           TopoDS_Shape aShape = aRefShape->GetValue();
181           if (!aShape.IsNull())
182           {
183             TopLoc_Location l;
184             Handle(Poly_Triangulation) T;
185             TopExp_Explorer ex;
186             for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
187               const TopoDS_Face& F = TopoDS::Face(ex.Current());
188               
189               BRepAdaptor_Surface surf(F);
190               if (surf.GetType() == GeomAbs_Sphere)
191               {
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         }
205       }
206
207       GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetBoundingBox(
208         myObj, theXmin, theXmax, theYmin, theYmax, theZmin, theZmax );
209
210       if (!Trtn.IsNull())
211       {
212         Handle(GEOM_Function) aRefShape = anObject->GetLastFunction();
213         if (!aRefShape.IsNull())
214         {
215           TopoDS_Shape aShape = aRefShape->GetValue();
216           if (!aShape.IsNull())
217           {
218             TopLoc_Location l;
219             Handle(Poly_Triangulation) T;
220             TopExp_Explorer ex;
221             for (ex.Init(aShape,TopAbs_FACE); ex.More(); ex.Next()) {
222               const TopoDS_Face& F = TopoDS::Face(ex.Current());
223               (*((Handle(BRep_TFace)*)&F.TShape()))->Triangulation(Trtn);
224               break;
225             }
226           }
227         }
228       }
229
230     }
231     catch( const SALOME::SALOME_Exception& e )
232     {
233       SalomeApp_Tools::QtCatchCorbaException( e );
234       return false;
235     }
236
237     return getOperation()->IsDone();
238   }
239 }
240
241 //=================================================================================
242 // function : buildPrs
243 // purpose  :
244 //=================================================================================
245 SALOME_Prs* MeasureGUI_BndBoxDlg::buildPrs()
246 {
247   double aXMin, aYMin, aZMin, aXMax, aYMax, aZMax;
248
249   if ( myObj->_is_nil() || !getParameters( aXMin, aXMax, aYMin, aYMax, aZMin, aZMax ) )
250     return 0;
251
252   TopoDS_Shape aShape = BRepPrimAPI_MakeBox( gp_Pnt( aXMin, aYMin, aZMin ),
253                                              gp_Pnt( aXMax, aYMax, aZMax ) ).Shape();
254        
255   return !aShape.IsNull() ? getDisplayer()->BuildPrs( aShape ) : 0;
256
257 }