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 : RepairGUI_DivideEdgeDlg.cxx
25 // Author : Lucien PIGNOLONI
30 #include "RepairGUI_DivideEdgeDlg.h"
32 #include "QAD_RightFrame.h"
33 #include "QAD_Desktop.h"
34 #include "OCCViewer_Viewer3d.h"
35 #include "SALOME_ListIteratorOfListIO.hxx"
37 #include "GEOMImpl_Types.hxx"
42 //=================================================================================
43 // class : RepairGUI_DivideEdgeDlg()
44 // purpose : Constructs a RepairGUI_DivideEdgeDlg which is a child of 'parent', with the
45 // name 'name' and widget flags set to 'f'.
46 // The dialog will by default be modeless, unless you set 'modal' to
47 // TRUE to construct a modal dialog.
48 //=================================================================================
49 RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_DIVIDE_EDGE")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setCaption(tr("GEOM_DIVIDE_EDGE_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
59 RadioButton1->setPixmap(image0);
60 RadioButton2->close(TRUE);
61 RadioButton3->close(TRUE);
63 GroupPoints = new DlgRef_1Sel_Ext(this, "GroupPoints");
64 GroupPoints->GroupBox1->setTitle(tr("GEOM_ADD_POINT"));
65 GroupPoints->TextLabel1->setText(tr("GEOM_EDGE"));
66 GroupPoints->PushButton1->setPixmap(image1);
67 GroupPoints->LineEdit1->setReadOnly( true );
69 myIsParameterGr = new QButtonGroup( 2, Qt::Vertical, GroupPoints );
70 myIsParameterGr->setFrameStyle( QFrame::NoFrame );
71 myIsParameterGr->setRadioButtonExclusive( true );
72 myIsParameterGr->insert( new QRadioButton( tr( "GEOM_BY_PARAMETER" ), myIsParameterGr ), 0 );
73 myIsParameterGr->insert( new QRadioButton( tr( "GEOM_BY_LENGTH" ), myIsParameterGr ), 1 );
74 myIsParameterGr->find( 0 )->toggle();
76 QGridLayout* aLay = new QGridLayout( 0, 1, 2, 0, 6, "aLay" );
77 myValEdt = new QAD_SpinBoxDbl( GroupPoints->GroupBox1, 0., 1., 0.1, 3 );
78 myValEdt->setValue( 0.5 );
79 QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->GroupBox1 );
80 aLay->addWidget( aLbl1, 0, 0 );
81 aLay->addWidget( myValEdt, 0, 1 );
83 Layout1->addWidget(GroupPoints, 2, 0);
84 GroupPoints->getGroupBoxLayout()->addMultiCellWidget(myIsParameterGr, 1, 1, 0, 2);
85 GroupPoints->getGroupBoxLayout()->addLayout( aLay, 2, 0 );
86 /***************************************************************/
92 //=================================================================================
93 // function : ~RepairGUI_DivideEdgeDlg()
94 // purpose : Destroys the object and frees any allocated resources
95 //=================================================================================
96 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
101 //=================================================================================
104 //=================================================================================
105 void RepairGUI_DivideEdgeDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
110 myObject = GEOM::GEOM_Object::_nil();
113 myGeomGUI->SetState( 0 );
116 /* signals and slots connections */
117 connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
118 connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
119 connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
121 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
122 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
124 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
125 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
127 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
129 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
133 //=================================================================================
134 // function : ClickOnOk()
135 // purpose : Same than click on apply but close this dialog.
136 //=================================================================================
137 void RepairGUI_DivideEdgeDlg::ClickOnOk()
139 if ( ClickOnApply() )
145 //=================================================================================
146 // function : ClickOnApply()
148 //=================================================================================
149 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
156 myEditCurrentArgument->setText("");
157 myObject = GEOM::GEOM_Object::_nil();
166 //=================================================================================
167 // function : ClickOnCancel()
169 //=================================================================================
170 void RepairGUI_DivideEdgeDlg::ClickOnCancel()
172 GEOMBase_Skeleton::ClickOnCancel();
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection as changed or other case
179 // : used only by SelectButtonC1A1 (LineEditC1A1)
180 //=================================================================================
181 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
183 myEditCurrentArgument->setText("");
185 myObject = GEOM::GEOM_Object::_nil();
188 if ( mySelection->IObjectCount() == 1 )
190 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject();
191 Standard_Boolean aRes;
192 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
193 if ( !CORBA::is_nil( aSelectedObj ) && aRes )
196 if ( myGeomBase->GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
198 const int aType = aShape.ShapeType();
199 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
201 GEOM::short_array anIndexes;
202 if ( mySelection->HasIndex( anIO ) ) // subshape selection
204 TColStd_IndexedMapOfInteger aMap;
205 mySelection->GetIndex( anIO, aMap );
207 myObject = aSelectedObj;
208 myEditCurrentArgument->setText( tr( "GEOM_EDGE" ) + "_1" );
210 else if ( aType == TopAbs_EDGE ) // single shape selection
213 myObject = aSelectedObj;
214 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
216 else // face, shell, solid or compound was selected, and NOT its subshape.
219 myObject = GEOM::GEOM_Object::_nil();
227 //=================================================================================
228 // function : SetEditCurrentArgument()
230 //=================================================================================
231 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
233 if( sender() == GroupPoints->PushButton1 )
235 GroupPoints->LineEdit1->setFocus();
236 myEditCurrentArgument = GroupPoints->LineEdit1;
238 SelectionIntoArgument();
242 //=================================================================================
243 // function : LineEditReturnPressed()
245 //=================================================================================
246 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
248 if( sender() == GroupPoints->LineEdit1 )
250 myEditCurrentArgument = GroupPoints->LineEdit1;
251 GEOMBase_Skeleton::LineEditReturnPressed();
256 //=================================================================================
257 // function : DeactivateActiveDialog()
259 //=================================================================================
260 void RepairGUI_DivideEdgeDlg::DeactivateActiveDialog()
262 myGeomGUI->SetState( -1 );
263 GEOMBase_Skeleton::DeactivateActiveDialog();
267 //=================================================================================
268 // function : ActivateThisDialog()
270 //=================================================================================
271 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
273 GEOMBase_Skeleton::ActivateThisDialog();
274 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
276 myObject = GEOM::GEOM_Object::_nil();
279 myGeomGUI->SetState( 0 );
284 //=================================================================================
285 // function : enterEvent()
286 // purpose : Mouse enter onto the dialog to activate it
287 //=================================================================================
288 void RepairGUI_DivideEdgeDlg::enterEvent(QEvent* e)
290 if ( !GroupConstructors->isEnabled() )
291 ActivateThisDialog();
295 //=================================================================================
296 // function : closeEvent()
298 //=================================================================================
299 void RepairGUI_DivideEdgeDlg::closeEvent(QCloseEvent* e)
301 myGeomGUI->SetState( -1 );
302 GEOMBase_Skeleton::closeEvent( e );
305 //=================================================================================
306 // function : createOperation
308 //=================================================================================
309 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
311 return getGeomEngine()->GetIHealingOperations( getStudyId() );
314 //=================================================================================
315 // function : isValid
317 //=================================================================================
318 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
320 return !myObject->_is_nil();
323 //=================================================================================
324 // function : execute
326 //=================================================================================
327 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
329 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge(
330 myObject, myIndex, myValEdt->value(), getIsByParameter() );
331 bool aResult = !anObj->_is_nil();
333 objects.push_back( anObj._retn() );
338 //=================================================================================
339 // function : getIsByParameter
341 //=================================================================================
342 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
344 return myIsParameterGr->find( 0 )->isOn();
347 //=================================================================================
348 // function : initSelection
350 //=================================================================================
351 void RepairGUI_DivideEdgeDlg::initSelection()
353 GEOM::GEOM_Object_var aNullGeomObject;
354 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects