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_MarkerDlg.cxx
25 // Author : Sergey LITONIN
29 #include "BasicGUI_MarkerDlg.h"
30 #include "DlgRef_SpinBox.h"
31 #include "QAD_Desktop.h"
32 #include "QAD_RightFrame.h"
33 #include "VTKViewer_ViewFrame.h"
34 #include "OCCViewer_ViewFrame.h"
35 #include "QAD_Config.h"
36 #include "GEOMImpl_Types.hxx"
37 #include "utilities.h"
42 #include <TopoDS_Vertex.hxx>
43 #include <TopoDS_Face.hxx>
44 #include <TColStd_IndexedMapOfInteger.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <BRep_Tool.hxx>
49 #include <Geom_Plane.hxx>
50 #include <GProp_GProps.hxx>
51 #include <BRepGProp.hxx>
53 //=================================================================================
54 // class : BasicGUI_MarkerDlg()
55 // purpose : Constructor
56 //=================================================================================
57 BasicGUI_MarkerDlg::BasicGUI_MarkerDlg( QWidget* theParent, SALOME_Selection* theSel )
58 : GEOMBase_Skeleton( theParent, "BasicGUI_MarkerDlg", theSel, false,
59 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
61 QPixmap iconCS1 ( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_MARKER" ) ) );
62 QPixmap iconCS2 ( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_MARKER2" ) ) );
63 QPixmap iconCS3 ( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_MARKER3" ) ) );
64 QPixmap iconSelect( QAD_Desktop::getResourceManager()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66 setCaption( tr( "CAPTION" ) );
68 GroupConstructors->setTitle( tr( "LOCALCS" ) );
69 RadioButton1->setPixmap( iconCS1 );
70 RadioButton2->setPixmap( iconCS2 );
71 RadioButton3->setPixmap( iconCS3 );
73 Group1 = new DlgRef_1Sel_QTD(this, "Group1");
74 Group1->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
75 Group1->TextLabel1->setText(tr("GEOM_OBJECT"));
76 Group1->PushButton1->setPixmap(iconSelect);
78 Group2 = new DlgRef_3Sel_QTD(this, "Group2");
79 Group2->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
80 Group2->TextLabel1->setText(tr("GEOM_POINT"));
81 Group2->TextLabel2->setText(tr("XDIR"));
82 Group2->TextLabel3->setText(tr("YDIR"));
83 Group2->PushButton1->setPixmap(iconSelect);
84 Group2->PushButton2->setPixmap(iconSelect);
85 Group2->PushButton3->setPixmap(iconSelect);
87 aMainGrp = new QGroupBox( 1, Qt::Horizontal, this );
88 aMainGrp->setFrameStyle( QFrame::NoFrame );
89 aMainGrp->setInsideMargin( 0 );
91 QGroupBox* anOriGrp = new QGroupBox( 1, Qt::Vertical, tr( "ORIGIN" ), aMainGrp );
92 new QLabel( tr( "GEOM_X" ), anOriGrp );
93 myData[ X ] = new DlgRef_SpinBox( anOriGrp );
94 new QLabel( tr( "GEOM_Y" ), anOriGrp );
95 myData[ Y ] = new DlgRef_SpinBox( anOriGrp );
96 new QLabel( tr( "GEOM_Z" ), anOriGrp );
97 myData[ Z ] = new DlgRef_SpinBox( anOriGrp );
99 QGroupBox* aXAxisGrp = new QGroupBox( 1, Qt::Vertical, tr( "XDIR" ), aMainGrp );
100 new QLabel( tr( "DX" ), aXAxisGrp );
101 myData[ DX1 ] = new DlgRef_SpinBox( aXAxisGrp );
102 new QLabel( tr( "DY" ), aXAxisGrp );
103 myData[ DY1 ] = new DlgRef_SpinBox( aXAxisGrp );
104 new QLabel( tr( "DZ" ), aXAxisGrp );
105 myData[ DZ1 ] = new DlgRef_SpinBox( aXAxisGrp );
107 QGroupBox* anYAxisGrp = new QGroupBox( 1, Qt::Vertical, tr( "YDIR" ), aMainGrp );
108 new QLabel( tr( "DX" ), anYAxisGrp );
109 myData[ DX2 ] = new DlgRef_SpinBox( anYAxisGrp );
110 new QLabel( tr( "DY" ), anYAxisGrp );
111 myData[ DY2 ] = new DlgRef_SpinBox( anYAxisGrp );
112 new QLabel( tr( "DZ" ), anYAxisGrp );
113 myData[ DZ2 ] = new DlgRef_SpinBox( anYAxisGrp );
115 Layout1->addWidget( aMainGrp, 2, 0 );
116 Layout1->addWidget( Group1, 2, 0 );
117 Layout1->addWidget( Group2, 2, 0 );
123 //=================================================================================
124 // function : ~BasicGUI_MarkerDlg()
125 // purpose : Destroys the object and frees any allocated resources
126 //=================================================================================
127 BasicGUI_MarkerDlg::~BasicGUI_MarkerDlg()
132 //=================================================================================
135 //=================================================================================
136 void BasicGUI_MarkerDlg::Init( SALOME_Selection* theSel )
138 myBlockPreview = false;
139 myConstructorId = -1;
140 myEditCurrentArgument = Group1->LineEdit1;
141 Group1->LineEdit1->setReadOnly( true );
142 Group2->LineEdit1->setReadOnly( true );
143 Group2->LineEdit2->setReadOnly( true );
144 Group2->LineEdit3->setReadOnly( true );
146 GeometryGUI* aGeomGUI = GeometryGUI::GetGeomGUI();
148 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
149 connect(Group1->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(Group2->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(Group2->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(Group2->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(Group1->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(Group2->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156 connect(Group2->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(Group2->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( onClose() ) );
160 connect( aGeomGUI, SIGNAL( SignalDeactivateActiveDialog() ), this, SLOT( onDeactivate() ) );
161 connect( aGeomGUI, SIGNAL( SignalCloseAllDialogs() ), this, SLOT( onClose() ) );
163 connect( buttonOk, SIGNAL( clicked() ), this, SLOT( onOk() ) );
164 connect( buttonApply, SIGNAL( clicked() ), this, SLOT( onApply() ) );
166 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
168 initName( tr( "LCS_NAME" ) );
170 QString aStr = QAD_CONFIG->getSetting( "Geometry:SettingsGeomStep" );
171 for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter )
173 anIter.data()->RangeStepAndValidator( -999.999, 999.999, aStr.toDouble(), 3 );
174 connect( anIter.data(), SIGNAL( valueChanged( double ) ),
175 this, SLOT( onValueChanged( double ) ) );
178 myBlockPreview = true;
179 for ( DataMap::iterator anIter = myData.begin(); anIter != myData.end(); ++anIter )
180 anIter.data()->SetValue( 0 );
181 myData[ DX1 ]->SetValue( 1 );
182 myData[ DY2 ]->SetValue( 1 );
183 myBlockPreview = false;
185 ConstructorsClicked( 0 );
187 QAD_ViewFrame* aFrame = QAD_Application::getDesktop()->getActiveApp()->
188 getActiveStudy()->getActiveStudyFrame()->getRightFrame()->getViewFrame();
190 VTKViewer_ViewFrame* aVTKFrame = dynamic_cast<VTKViewer_ViewFrame*>( aFrame );
193 aVTKFrame->AdjustTrihedrons( true );
197 OCCViewer_ViewFrame* aOCCFrame = dynamic_cast<OCCViewer_ViewFrame*>( aFrame );
199 aOCCFrame->AdjustTrihedrons( true );
202 //=================================================================================
203 // function : ConstructorsClicked()
204 // purpose : Radio button management
205 //=================================================================================
206 void BasicGUI_MarkerDlg::ConstructorsClicked( int constructorId )
208 if ( myConstructorId == constructorId && myConstructorId == 0 )
210 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
211 activate( GEOM_MARKER );
216 myConstructorId = constructorId;
218 disconnect(mySelection, 0, this, 0);
220 switch (constructorId)
228 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
229 activate( GEOM_MARKER );
240 myEditCurrentArgument = Group1->LineEdit1;
241 Group1->LineEdit1->setText("");
251 globalSelection( GEOM_POINT );
252 myEditCurrentArgument = Group2->LineEdit1;
253 Group2->LineEdit1->setText("");
254 Group2->LineEdit2->setText("");
255 Group2->LineEdit3->setText("");
260 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
264 //=================================================================================
267 //=================================================================================
268 void BasicGUI_MarkerDlg::onOk()
274 //=======================================================================
275 // function : onClose()
277 //=======================================================================
278 void BasicGUI_MarkerDlg::onClose()
280 GEOMBase_Skeleton::ClickOnCancel();
283 //=================================================================================
284 // function : onApply()
286 //=================================================================================
287 bool BasicGUI_MarkerDlg::onApply()
293 ConstructorsClicked( getConstructorId() );
298 //=================================================================================
299 // function : onSelectionDone0()
300 // purpose : Reaction on selection when first method of creation is current one
301 //=================================================================================
302 void BasicGUI_MarkerDlg::onSelectionDone0()
304 if ( mySelection->IObjectCount() == 1 )
307 Standard_Boolean aRes = Standard_False;
308 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
309 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
311 if ( aRes && !aSelectedObj->_is_nil() )
314 if ( myGeomBase->GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
316 if ( aSelectedObj->GetType() == GEOM_MARKER && aShape.ShapeType() == TopAbs_FACE )
318 TopoDS_Face aFace = TopoDS::Face( aShape );
319 Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast( BRep_Tool::Surface( aFace ) );
321 if ( !aPlane.IsNull() )
323 gp_Ax3 anAx3 = aPlane->Pln().Position();
324 gp_Pnt aLoc = anAx3.Location();
325 gp_Dir aXDir = anAx3.XDirection();
326 gp_Dir aYDir = anAx3.YDirection();
328 myData[ X ]->SetValue( aLoc.X() );
329 myData[ Y ]->SetValue( aLoc.Y() );
330 myData[ Z ]->SetValue( aLoc.Z() );
332 myData[ DX1 ]->SetValue( aXDir.X() );
333 myData[ DY1 ]->SetValue( aXDir.Y() );
334 myData[ DZ1 ]->SetValue( aXDir.Z() );
336 myData[ DX2 ]->SetValue( aYDir.X() );
337 myData[ DY2 ]->SetValue( aYDir.Y() );
338 myData[ DZ2 ]->SetValue( aYDir.Z() );
339 //mySelection->ClearIObjects();
344 if ( mySelection->HasIndex( anIO ) )
346 TColStd_IndexedMapOfInteger aMap;
347 mySelection->GetIndex( anIO, aMap );
348 if ( aMap.Extent() == 1 )
350 int anIndex = aMap( 1 );
351 TopTools_IndexedMapOfShape aShapes;
352 TopExp::MapShapes( aShape, aShapes );
353 aShape = aShapes.FindKey( anIndex );
354 //mySelection->ClearIObjects();
358 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX )
360 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
361 myData[ X ]->SetValue( aPnt.X() );
362 myData[ Y ]->SetValue( aPnt.Y() );
363 myData[ Z ]->SetValue( aPnt.Z() );
374 //=================================================================================
375 // function : onSelectionDone()
376 // purpose : Called when selection as changed or other case
377 //=================================================================================
378 void BasicGUI_MarkerDlg::onSelectionDone()
380 if ( getConstructorId() == 0 )
387 myEditCurrentArgument->setText("");
390 if ( mySelection->IObjectCount() == 1 ) {
391 Standard_Boolean aRes = Standard_False;
392 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
393 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
395 if ( !CORBA::is_nil( aSelectedObj ) && aRes ) {
396 aName = GEOMBase::GetName( aSelectedObj );
398 if ( myGeomBase->GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) ) {
399 GEOM::short_array anIndexes;
400 if ( mySelection->HasIndex( anIO ) ) {
401 TColStd_IndexedMapOfInteger aMap;
402 mySelection->GetIndex( anIO, aMap );
403 int anIndex = aMap( 1 );
404 TopTools_IndexedMapOfShape aShapes;
405 TopExp::MapShapes( aShape, aShapes );
406 aShape = aShapes.FindKey( anIndex );
409 if ( getConstructorId() == 1 ) {
410 if ( !aShape.IsNull() ) {
412 if (aShape.ShapeType() == TopAbs_VERTEX) {
413 aPnt = BRep_Tool::Pnt(TopoDS::Vertex(aShape));
416 GProp_GProps aSystem;
417 if (aShape.ShapeType() == TopAbs_EDGE || aShape.ShapeType() == TopAbs_WIRE)
418 BRepGProp::LinearProperties(aShape, aSystem);
419 else if (aShape.ShapeType() == TopAbs_FACE || aShape.ShapeType() == TopAbs_SHELL)
420 BRepGProp::SurfaceProperties(aShape, aSystem);
422 BRepGProp::VolumeProperties(aShape, aSystem);
424 aPnt = aSystem.CentreOfMass();
428 anAx3.Transform(aShape.Location().Transformation());
429 if(aShape.ShapeType() == TopAbs_FACE) {
430 Handle(Geom_Surface) aGS = BRep_Tool::Surface( TopoDS::Face( aShape ) );
431 if (!aGS.IsNull() && aGS->IsKind( STANDARD_TYPE( Geom_Plane ) ) ) {
432 Handle(Geom_Plane) aGPlane = Handle(Geom_Plane)::DownCast( aGS );
433 gp_Pln aPln = aGPlane->Pln();
434 anAx3 = aPln.Position();
438 gp_Dir aDirX = anAx3.XDirection();
439 gp_Dir aDirY = anAx3.YDirection();
441 myData[ X ]->SetValue( aPnt.X() );
442 myData[ Y ]->SetValue( aPnt.Y() );
443 myData[ Z ]->SetValue( aPnt.Z() );
445 myData[ DX1 ]->SetValue( aDirX.X() );
446 myData[ DY1 ]->SetValue( aDirX.Y() );
447 myData[ DZ1 ]->SetValue( aDirX.Z() );
449 myData[ DX2 ]->SetValue( aDirY.X() );
450 myData[ DY2 ]->SetValue( aDirY.Y() );
451 myData[ DZ2 ]->SetValue( aDirY.Z() );
453 myEditCurrentArgument->setText( aName );
456 else if ( getConstructorId() == 2 ) {
457 if (myEditCurrentArgument == Group2->LineEdit1) {
458 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
459 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( aShape ) );
460 myData[ X ]->SetValue( aPnt.X() );
461 myData[ Y ]->SetValue( aPnt.Y() );
462 myData[ Z ]->SetValue( aPnt.Z() );
463 myEditCurrentArgument->setText( aName );
466 else if (myEditCurrentArgument == Group2->LineEdit2) {
467 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
468 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(TopoDS::Edge(aShape)));
469 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(TopoDS::Edge(aShape)));
470 gp_Dir aDir(gp_Vec(aP1, aP2));
472 myData[ DX1 ]->SetValue( aDir.X() );
473 myData[ DY1 ]->SetValue( aDir.Y() );
474 myData[ DZ1 ]->SetValue( aDir.Z() );
475 myEditCurrentArgument->setText( aName );
478 else if (myEditCurrentArgument == Group2->LineEdit3) {
479 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_EDGE ) {
480 gp_Pnt aP1 = BRep_Tool::Pnt(TopExp::FirstVertex(TopoDS::Edge(aShape)));
481 gp_Pnt aP2 = BRep_Tool::Pnt(TopExp::LastVertex(TopoDS::Edge(aShape)));
482 gp_Dir aDir(gp_Vec(aP1, aP2));
484 myData[ DX2 ]->SetValue( aDir.X() );
485 myData[ DY2 ]->SetValue( aDir.Y() );
486 myData[ DZ2 ]->SetValue( aDir.Z() );
487 myEditCurrentArgument->setText( aName );
498 //=================================================================================
499 // function : SetEditCurrentArgument()
501 //=================================================================================
502 void BasicGUI_MarkerDlg::SetEditCurrentArgument()
504 QPushButton* send = (QPushButton*)sender();
506 if(send == Group1->PushButton1) {
507 myEditCurrentArgument = Group1->LineEdit1;
510 else if(send == Group2->PushButton1) {
511 myEditCurrentArgument = Group2->LineEdit1;
512 globalSelection( GEOM_POINT );
514 else if(send == Group2->PushButton2) {
515 myEditCurrentArgument = Group2->LineEdit2;
516 globalSelection( GEOM_LINE );
518 else if(send == Group2->PushButton3) {
519 myEditCurrentArgument = Group2->LineEdit3;
520 globalSelection( GEOM_LINE );
523 myEditCurrentArgument->setFocus();
527 //=================================================================================
528 // function : LineEditReturnPressed()
530 //=================================================================================
531 void BasicGUI_MarkerDlg::LineEditReturnPressed()
533 QLineEdit* send = (QLineEdit*)sender();
535 myEditCurrentArgument = send;
536 GEOMBase_Skeleton::LineEditReturnPressed();
539 //=================================================================================
540 // function : onActivate()
542 //=================================================================================
543 void BasicGUI_MarkerDlg::onActivate()
545 GEOMBase_Skeleton::ActivateThisDialog();
546 connect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
548 ConstructorsClicked( getConstructorId() );
551 //=================================================================================
552 // function : onDeactivate()
553 // purpose : public slot to deactivate if active
554 //=================================================================================
555 void BasicGUI_MarkerDlg::onDeactivate()
557 GEOMBase_Skeleton::DeactivateActiveDialog();
560 //=================================================================================
561 // function : enterEvent()
563 //=================================================================================
564 void BasicGUI_MarkerDlg::enterEvent(QEvent* e)
566 if ( !GroupConstructors->isEnabled() )
570 //=================================================================================
571 // function : createOperation
573 //=================================================================================
574 GEOM::GEOM_IOperations_ptr BasicGUI_MarkerDlg::createOperation()
576 return getGeomEngine()->GetIBasicOperations( getStudyId() );
579 //=================================================================================
580 // function : isValid
582 //=================================================================================
583 bool BasicGUI_MarkerDlg::isValid( QString& msg )
588 //=================================================================================
589 // function : execute
591 //=================================================================================
592 bool BasicGUI_MarkerDlg::execute( ObjectList& objects )
594 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IBasicOperations::_narrow(
595 getOperation() )->MakeMarker( myData[ X ]->GetValue(), myData[ Y ]->GetValue(), myData[ Z ]->GetValue(),
596 myData[ DX1 ]->GetValue(), myData[ DY1 ]->GetValue(), myData[ DZ1 ]->GetValue(),
597 myData[ DX2 ]->GetValue(), myData[ DY2 ]->GetValue(), myData[ DZ2 ]->GetValue() );
599 if ( !anObj->_is_nil() )
600 objects.push_back( anObj._retn() );
605 //=================================================================================
606 // function : closeEvent
608 //=================================================================================
609 void BasicGUI_MarkerDlg::closeEvent( QCloseEvent* e )
611 GEOMBase_Skeleton::closeEvent( e );
614 //=================================================================================
615 // function : onValueChanged
617 //=================================================================================
618 void BasicGUI_MarkerDlg::onValueChanged( double )
623 //=================================================================================
624 // function : displayPreview
626 //=================================================================================
627 void BasicGUI_MarkerDlg::displayPreview ( const bool activate,
629 const bool toRemoveFromEngine,
630 const double lineWidth )
632 if ( !myBlockPreview )
634 GEOMBase_Skeleton::displayPreview( activate, update, toRemoveFromEngine, lineWidth );
635 if ( myConstructorId == 0 )
637 GEOMBase_Skeleton::activate( GEOM_MARKER );