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 : BasicGUI_WorkingPlaneDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "BasicGUI_WorkingPlaneDlg.h"
33 #include "OCCViewer_Viewer3d.h"
34 #include "OCCViewer_ViewPort3d.h"
35 #include "QAD_StudyFrame.h"
36 #include "QAD_RightFrame.h"
37 #include "QAD_Desktop.h"
39 #include <Geom_Surface.hxx>
40 #include <Geom_Plane.hxx>
42 #include <TopoDS_Face.hxx>
43 #include <TopoDS_Edge.hxx>
44 #include <TopoDS_Vertex.hxx>
46 #include <BRep_Tool.hxx>
50 #include <V3d_View.hxx>
52 #include "GEOMImpl_Types.hxx"
54 #include <qcheckbox.h>
56 //=================================================================================
57 // class : BasicGUI_WorkingPlaneDlg()
58 // purpose : Constructs a BasicGUI_WorkingPlaneDlg 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 BasicGUI_WorkingPlaneDlg::BasicGUI_WorkingPlaneDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
64 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
66 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
67 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_FACE")));
68 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_VECTOR")));
69 QPixmap image3(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_WPLANE_ORIGIN")));
71 setCaption(tr("GEOM_WPLANE_TITLE"));
73 /***************************************************************/
74 GroupConstructors->setTitle(tr("GEOM_WPLANE"));
75 RadioButton1->setPixmap(image1);
76 RadioButton2->setPixmap(image2);
77 RadioButton3->setPixmap(image3);
79 Group1 = new DlgRef_1Sel_QTD(this, "Group1");
80 Group1->GroupBox1->setTitle(tr("GEOM_WPLANE_FACE"));
81 Group1->TextLabel1->setText(tr("GEOM_SELECTION"));
82 Group1->PushButton1->setPixmap(image0);
83 Group1->LineEdit1->setReadOnly( true );
85 Group2 = new DlgRef_2Sel_QTD(this, "Group2");
86 Group2->GroupBox1->setTitle(tr("GEOM_WPLANE_VECTOR"));
87 Group2->TextLabel1->setText(tr("GEOM_WPLANE_VX"));
88 Group2->TextLabel2->setText(tr("GEOM_WPLANE_VZ"));
89 Group2->PushButton1->setPixmap(image0);
90 Group2->PushButton2->setPixmap(image0);
91 Group2->LineEdit1->setReadOnly( true );
92 Group2->LineEdit2->setReadOnly( true );
94 Group3 = new DlgRef_3Check_QTD(this, "Group3");
95 Group3->GroupBox1->setTitle(tr("GEOM_WPLANE_ORIGIN"));
96 Group3->RadioButton1->setText(tr("GEOM_WPLANE_OXY"));
97 Group3->RadioButton2->setText(tr("GEOM_WPLANE_OYZ"));
98 Group3->RadioButton3->setText(tr("GEOM_WPLANE_OZX"));
100 Layout1->addWidget(Group1, 1, 0);
101 Layout1->addWidget(Group2, 1, 0);
102 Layout1->addWidget(Group3, 1, 0);
103 /***************************************************************/
108 //=================================================================================
109 // function : ~BasicGUI_WorkingPlaneDlg()
110 // purpose : Destroys the object and frees any allocated resources
111 //=================================================================================
112 BasicGUI_WorkingPlaneDlg::~BasicGUI_WorkingPlaneDlg()
116 //=================================================================================
119 //=================================================================================
120 void BasicGUI_WorkingPlaneDlg::Init()
123 myEditCurrentArgument = Group1->LineEdit1;
124 myWPlane = GeometryGUI::GetGeomGUI()->GetWorkingPlane();
126 myGeomGUI->SetState( 0 );
128 myFace = GEOM::GEOM_Object::_nil();
129 myVectX = GEOM::GEOM_Object::_nil();
130 myVectZ = GEOM::GEOM_Object::_nil();
134 /* Filter definition */
135 globalSelection( GEOM_PLANE );
137 /* signals and slots connections */
138 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
139 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
140 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
141 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
143 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
144 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
146 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
147 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
149 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
150 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(Group2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
152 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(Group3->GroupBox1, SIGNAL(clicked(int)), this, SLOT(GroupClicked(int)));
156 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
158 initName( tr( "GEOM_WPLANE" ) );
159 ConstructorsClicked(0);
162 //=================================================================================
163 // function : ConstructorsClicked()
164 // purpose : Radio button management
165 //=================================================================================
166 void BasicGUI_WorkingPlaneDlg::ConstructorsClicked(int constructorId)
168 disconnect(mySelection, 0, this, 0);
169 myGeomGUI->SetState( 0 );
171 switch (constructorId)
175 globalSelection( GEOM_PLANE );
182 myEditCurrentArgument = Group1->LineEdit1;
183 Group1->LineEdit1->setText("");
184 myFace = GEOM::GEOM_Object::_nil();
186 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
191 globalSelection( GEOM_LINE );
198 myEditCurrentArgument = Group2->LineEdit1;
199 Group2->LineEdit1->setText("");
200 Group2->LineEdit2->setText("");
201 myVectX = GEOM::GEOM_Object::_nil();
202 myVectZ = GEOM::GEOM_Object::_nil();
204 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
214 Group3->RadioButton1->setChecked(true);
222 //=================================================================================
223 // function : GroupClicked()
224 // purpose : Radio button management
225 //=================================================================================
226 void BasicGUI_WorkingPlaneDlg::GroupClicked(int groupId)
228 aOriginType = groupId;
231 //=================================================================================
232 // function : ClickOnOk()
234 //=================================================================================
235 void BasicGUI_WorkingPlaneDlg::ClickOnOk()
237 if ( ClickOnApply() )
241 //=================================================================================
242 // function : ClickOnApply()
244 //=================================================================================
245 bool BasicGUI_WorkingPlaneDlg::ClickOnApply()
247 buttonApply->setFocus();
248 QAD_Application::getDesktop()->putInfo(tr(""));
249 const int id = getConstructorId();
252 if ( !CORBA::is_nil( myFace ) ) {
253 TopoDS_Face aPlaneShape;
254 if ( GEOMBase::GetShape( myFace, aPlaneShape, TopAbs_FACE ) ) {
255 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aPlaneShape ) );
256 if ( !aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
257 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
258 gp_Pln aPln = aGPlane->Pln();
260 myWPlane = aPln.Position();
261 GeometryGUI::GetGeomGUI()->SetWorkingPlane(myWPlane);
262 GeometryGUI::GetGeomGUI()->ActiveWorkingPlane();
267 } else if (id == 1) {
268 if ( CORBA::is_nil( myVectX ) || CORBA::is_nil( myVectZ ) ) {
269 showError( "Two vectors have to be selected" );
273 TopoDS_Edge aVectX, aVectZ;
274 TopoDS_Vertex V1, V2;
276 if (GEOMBase::GetShape( myVectX, aVectX, TopAbs_EDGE ) &&
277 GEOMBase::GetShape( myVectZ, aVectZ, TopAbs_EDGE )) {
278 TopExp::Vertices(aVectZ, V1, V2, Standard_True);
279 if (!V1.IsNull() && !V2.IsNull())
280 aVZ = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
282 showError( "Bad OZ vector" );
286 TopExp::Vertices(aVectX, V1, V2, Standard_True);
287 if (!V1.IsNull() && !V2.IsNull())
288 aVX = gp_Vec(BRep_Tool::Pnt(V1), BRep_Tool::Pnt(V2));
290 showError( "Bad OX vector" );
294 gp_Dir aDirZ = gp_Dir(aVZ.X(), aVZ.Y(), aVZ.Z());
295 gp_Dir aDirX = gp_Dir(aVX.X(), aVX.Y(), aVX.Z());
297 if (aDirX.IsParallel(aDirZ, Precision::Confusion())) {
298 showError( "Parallel vectors selected" );
302 myWPlane = gp_Ax3(BRep_Tool::Pnt(V1), aDirZ, aDirX);
304 GeometryGUI::GetGeomGUI()->SetWorkingPlane(myWPlane);
305 GeometryGUI::GetGeomGUI()->ActiveWorkingPlane();
308 } else if (id == 2) {
309 gp_Pnt P1 = gp_Pnt(0., 0., 0.);
312 if (aOriginType == 1) {
313 aDirZ = gp_Dir(0., 0., 1.);
314 aDirX = gp_Dir(1., 0., 0.);
316 else if (aOriginType == 2) {
317 aDirZ = gp_Dir(1., 0., 0.);
318 aDirX = gp_Dir(0., 1., 0.);
320 else if (aOriginType == 0) {
321 aDirZ = gp_Dir(0., 1., 0.);
322 aDirX = gp_Dir(0., 0., 1.);
325 myWPlane = gp_Ax3(P1, aDirZ, aDirX);
327 GeometryGUI::GetGeomGUI()->SetWorkingPlane(myWPlane);
328 GeometryGUI::GetGeomGUI()->ActiveWorkingPlane();
334 //=================================================================================
335 // function : SelectionIntoArgument()
336 // purpose : Called when selection as changed or other case
337 //=================================================================================
338 void BasicGUI_WorkingPlaneDlg::SelectionIntoArgument()
340 myEditCurrentArgument->setText("");
342 const int id = getConstructorId();
343 if ( mySelection->IObjectCount() != 1 ) {
345 myFace = GEOM::GEOM_Object::_nil();
347 if (myEditCurrentArgument == Group2->LineEdit1)
348 myVectX = GEOM::GEOM_Object::_nil();
349 else if (myEditCurrentArgument == Group2->LineEdit2)
350 myVectZ = GEOM::GEOM_Object::_nil();
356 Standard_Boolean aRes = Standard_False;
357 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(mySelection->firstIObject(), aRes);
359 if(!aRes || CORBA::is_nil( aSelectedObject ))
362 if(myEditCurrentArgument == Group1->LineEdit1)
363 myFace = aSelectedObject;
364 else if(myEditCurrentArgument == Group2->LineEdit1)
365 myVectX = aSelectedObject;
366 else if(myEditCurrentArgument == Group2->LineEdit2)
367 myVectZ = aSelectedObject;
369 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
373 //=================================================================================
374 // function : SetEditCurrentArgument()
376 //=================================================================================
377 void BasicGUI_WorkingPlaneDlg::SetEditCurrentArgument()
379 QPushButton* send = (QPushButton*)sender();
381 if(send == Group1->PushButton1) {
382 myEditCurrentArgument = Group1->LineEdit1;
383 globalSelection( GEOM_PLANE );
385 else if(send == Group2->PushButton1) {
386 myEditCurrentArgument = Group2->LineEdit1;
387 globalSelection( GEOM_LINE );
389 else if(send == Group2->PushButton2) {
390 myEditCurrentArgument = Group2->LineEdit2;
391 globalSelection( GEOM_LINE );
394 myEditCurrentArgument->setFocus();
395 SelectionIntoArgument();
399 //=================================================================================
400 // function : LineEditReturnPressed()
402 //=================================================================================
403 void BasicGUI_WorkingPlaneDlg::LineEditReturnPressed()
405 QLineEdit* send = (QLineEdit*)sender();
406 if(send == Group1->LineEdit1 || send == Group2->LineEdit1 || send == Group2->LineEdit2) {
407 myEditCurrentArgument = send;
408 GEOMBase_Skeleton::LineEditReturnPressed();
413 //=================================================================================
414 // function : ActivateThisDialog()
416 //=================================================================================
417 void BasicGUI_WorkingPlaneDlg::ActivateThisDialog( )
419 GEOMBase_Skeleton::ActivateThisDialog();
420 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
422 ConstructorsClicked( getConstructorId() );
426 //=================================================================================
427 // function : DeactivateActiveDialog()
428 // purpose : public slot to deactivate if active
429 //=================================================================================
430 void BasicGUI_WorkingPlaneDlg::DeactivateActiveDialog()
432 myGeomGUI->SetState( -1 );
433 GEOMBase_Skeleton::DeactivateActiveDialog();
436 //=======================================================================
437 // function : ClickOnCancel()
439 //=======================================================================
440 void BasicGUI_WorkingPlaneDlg::ClickOnCancel()
442 GEOMBase_Skeleton::ClickOnCancel();
445 //=================================================================================
446 // function : enterEvent()
448 //=================================================================================
449 void BasicGUI_WorkingPlaneDlg::enterEvent(QEvent* e)
451 if ( !GroupConstructors->isEnabled() )
452 ActivateThisDialog();
455 //=================================================================================
456 // function : closeEvent
458 //=================================================================================
459 void BasicGUI_WorkingPlaneDlg::closeEvent( QCloseEvent* e )
461 myGeomGUI->SetState( -1 );
462 GEOMBase_Skeleton::closeEvent( e );