1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : MeasureGUI_DistanceDlg.cxx
25 // Author : Nicolas REJNERI
29 #include "MeasureGUI_DistanceDlg.h"
30 #include "MeasureGUI_2Sel1LineEdit_QTD.h"
32 #include "GEOM_Displayer.h"
33 #include "QAD_RightFrame.h"
34 #include "QAD_Desktop.h"
35 #include "OCCViewer_Viewer3d.h"
36 #include "OCCViewer_Prs.h"
37 #include "SALOMEGUI_QtCatchCorbaException.hxx"
39 #include <Geom_Plane.hxx>
40 #include <TopoDS_Edge.hxx>
41 #include <AIS_LengthDimension.hxx>
42 #include <BRepBuilderAPI_MakeEdge.hxx>
43 #include <BRepBuilderAPI_MakeVertex.hxx>
44 #include <AIS_ListIteratorOfListOfInteractive.hxx>
45 #include <gce_MakePln.hxx>
46 #include <Precision.hxx>
48 #include "utilities.h"
50 #include <qlineedit.h>
52 #include <qpushbutton.h>
53 #include <qradiobutton.h>
54 #include <qbuttongroup.h>
56 //=================================================================================
57 // class : MeasureGUI_DistanceDlg()
58 // purpose : Constructs a MeasureGUI_DistanceDlg 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_DistanceDlg::MeasureGUI_DistanceDlg( QWidget* parent, SALOME_Selection* Sel )
64 : MeasureGUI_Skeleton( parent, "MeasureGUI_DistanceDlg", Sel )
66 QPixmap image0( QAD_Desktop::getResourceManager()->loadPixmap(
67 "GEOM",tr( "ICON_DLG_MINDIST" ) ) );
68 QPixmap image1( QAD_Desktop::getResourceManager()->loadPixmap(
69 "GEOM",tr( "ICON_SELECT" ) ) );
71 setCaption( tr( "GEOM_MINDIST_TITLE" ) );
73 /***************************************************************/
75 GroupConstructors->setTitle( tr( "GEOM_DISTANCE" ) );
76 RadioButton1->setPixmap( image0 );
78 myGrp = new MeasureGUI_2Sel1LineEdit_QTD( this, "myGrp" );
79 myGrp->GroupBox1->setTitle( tr( "GEOM_MINDIST_OBJ" ) );
80 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT_I" ).arg( "1" ) );
81 myGrp->TextLabel2->setText( tr( "GEOM_OBJECT_I" ).arg( "2" ) );
82 myGrp->TextLabel3->setText( tr( "GEOM_LENGTH" ) );
83 myGrp->LineEdit3->setReadOnly( TRUE );
84 myGrp->PushButton1->setPixmap( image1 );
85 myGrp->PushButton2->setPixmap( image1 );
86 myGrp->LineEdit1->setReadOnly( true );
87 myGrp->LineEdit2->setReadOnly( true );
89 Layout1->addWidget( myGrp, 1, 0 );
91 /***************************************************************/
98 //=================================================================================
99 // function : ~MeasureGUI_DistanceDlg()
100 // purpose : Destroys the object and frees any allocated resources
101 //=================================================================================
102 MeasureGUI_DistanceDlg::~MeasureGUI_DistanceDlg()
107 //=================================================================================
110 //=================================================================================
111 void MeasureGUI_DistanceDlg::Init( SALOME_Selection* Sel )
113 mySelBtn = myGrp->PushButton1;
114 mySelEdit = myGrp->LineEdit1;
115 mySelBtn2 = myGrp->PushButton2;
116 mySelEdit2 = myGrp->LineEdit2;
118 myEditCurrentArgument = mySelEdit;
120 connect( mySelEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
121 connect( mySelBtn2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
123 MeasureGUI_Skeleton::Init( Sel );
128 //=================================================================================
129 // function : SelectionIntoArgument()
130 // purpose : Called when selection has changed
131 //=================================================================================
132 void MeasureGUI_DistanceDlg::SelectionIntoArgument()
134 Standard_Boolean testResult = Standard_False;
135 GEOM::GEOM_Object_var aSelectedObject =
136 GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
139 aSelectedObject = GEOM::GEOM_Object::_nil();
141 if ( myEditCurrentArgument == mySelEdit )
142 myObj = aSelectedObject;
144 myObj2 = aSelectedObject;
149 //=================================================================================
150 // function : processObject()
151 // purpose : Fill dialogs fileds in accordance with myObj and myObj2
152 //=================================================================================
153 void MeasureGUI_DistanceDlg::processObject()
155 myGrp->LineEdit1->setText( !myObj->_is_nil() ? GEOMBase::GetName( myObj ) : "" );
156 myGrp->LineEdit2->setText( !myObj2->_is_nil() ? GEOMBase::GetName( myObj2 ) : "" );
160 if ( getParameters( aDist, aPnt1, aPnt2 ) )
162 myGrp->LineEdit3->setText( QString( "%1" ).arg( aDist ) );
167 myGrp->LineEdit3->setText( "" );
173 //=================================================================================
174 // function : getParameters()
175 // purpose : Get distance between objects
176 //=================================================================================
177 bool MeasureGUI_DistanceDlg::getParameters( double& theDistance,
182 if ( !isValid( msg ) )
188 double x1, y1, z1, x2, y2, z2;
189 theDistance = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() )->GetMinDistance(
190 myObj, myObj2, x1, y1, z1, x2, y2, z2 );
192 thePnt1.SetCoord( x1, y1, z1 );
193 thePnt2.SetCoord( x2, y2, z2 );
195 catch( const SALOME::SALOME_Exception& e )
197 QtCatchCorbaException( e );
201 return getOperation()->IsDone();
206 //=================================================================================
207 // function : SetEditCurrentArgument()
209 //=================================================================================
210 void MeasureGUI_DistanceDlg::SetEditCurrentArgument()
212 QPushButton* send = ( QPushButton* )sender();
214 if( send == mySelBtn )
216 mySelEdit->setFocus();
217 myEditCurrentArgument = mySelEdit;
221 mySelEdit2->setFocus();
222 myEditCurrentArgument = mySelEdit2;
225 SelectionIntoArgument();
229 //=================================================================================
230 // function : LineEditReturnPressed()
232 //=================================================================================
233 void MeasureGUI_DistanceDlg::LineEditReturnPressed()
235 QLineEdit* send = ( QLineEdit* )sender();
237 if( send == mySelEdit )
238 myEditCurrentArgument = mySelEdit;
240 myEditCurrentArgument = mySelEdit2;
242 if ( GEOMBase::SelectionByNameInDialogs( this, mySelEdit->text(), mySelection ) )
243 mySelEdit->setText( mySelEdit->text() );
247 //=================================================================================
248 // function : buildPrs()
250 //=================================================================================
251 SALOME_Prs* MeasureGUI_DistanceDlg::buildPrs()
254 gp_Pnt aPnt1( 0, 0, 0 ), aPnt2( 0, 0, 0 );
256 if ( myObj->_is_nil() || myObj2->_is_nil() || !getParameters( aDist, aPnt1, aPnt2 ) ||
257 QAD_Application::getDesktop()->getActiveStudy()->getActiveStudyFrame()->getTypeView() != VIEW_OCC )
264 BRepBuilderAPI_MakeVertex aMaker( aPnt1 );
265 return getDisplayer()->BuildPrs( aMaker.Vertex() );
269 BRepBuilderAPI_MakeEdge MakeEdge( aPnt1, aPnt2 );
270 TopoDS_Vertex aVert1 = BRepBuilderAPI_MakeVertex( aPnt1 );
271 TopoDS_Vertex aVert2 = BRepBuilderAPI_MakeVertex( aPnt2 );
274 aLabel.sprintf( "%.1f", aDist );
276 gp_Pnt aPnt3( ( aPnt1.X() + aPnt2.X() ) / 2,
277 ( aPnt1.Y() + aPnt2.Y() ) / 2,
278 ( aPnt1.Z() + aPnt2.Z() ) / 2 + 100 );
281 gp_Vec va( aPnt3, aPnt1 );
282 gp_Vec vb( aPnt3, aPnt2 );
284 if ( va.IsParallel( vb, Precision::Angular() ) )
286 aPnt3.SetY( ( aPnt1.Y() + aPnt2.Y() ) / 2 + 100 );
287 aPnt3.SetZ( ( aPnt1.Z() + aPnt2.Z() ) / 2 );
290 gce_MakePln gce_MP( aPnt1, aPnt2, aPnt3 );
291 Handle( Geom_Plane ) P = new Geom_Plane( gce_MP.Value() );
293 Handle( AIS_LengthDimension ) anIO = new AIS_LengthDimension(
294 aVert1, aVert2, P, aDist, TCollection_ExtendedString( (Standard_CString)aLabel.latin1() ) );
296 QAD_ViewFrame* vf = GEOM_Displayer::GetActiveView();
297 OCCViewer_Prs* aPrs = dynamic_cast<OCCViewer_Prs*>( vf->CreatePrs( 0 ) );
300 aPrs->AddObject( anIO );
305 catch( Standard_Failure )
311 //=================================================================================
312 // function : isValid()
314 //=================================================================================
315 bool MeasureGUI_DistanceDlg::isValid( QString& msg )
317 return MeasureGUI_Skeleton::isValid( msg ) && !myObj2->_is_nil();