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