1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : RepairGUI_DivideEdgeDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
27 #include "RepairGUI_DivideEdgeDlg.h"
30 #include <GeometryGUI.h>
32 #include <SalomeApp_DoubleSpinBox.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
36 #include <SUIT_Session.h>
37 #include <SUIT_ResourceMgr.h>
39 #include <GEOMImpl_Types.hxx>
42 #include <Geom_Curve.hxx>
46 #include <TopoDS_Edge.hxx>
47 #include <BRep_Tool.hxx>
48 #include <TopTools_IndexedMapOfShape.hxx>
49 #include <BRepBuilderAPI_MakeVertex.hxx>
50 #include <TColStd_IndexedMapOfInteger.hxx>
52 //=================================================================================
53 // class : RepairGUI_DivideEdgeDlg()
54 // purpose : Constructs a RepairGUI_DivideEdgeDlg which is a child of 'parent', with the
55 // name 'name' and widget flags set to 'f'.
56 // The dialog will by default be modeless, unless you set 'modal' to
57 // TRUE to construct a modal dialog.
58 //=================================================================================
59 RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
61 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
63 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DIVIDE_EDGE" ) ) );
64 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
66 setWindowTitle( tr( "GEOM_DIVIDE_EDGE_TITLE" ) );
68 /***************************************************************/
69 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
70 mainFrame()->RadioButton1->setIcon( image0 );
71 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
72 mainFrame()->RadioButton2->close();
73 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
74 mainFrame()->RadioButton3->close();
76 GroupPoints = new DlgRef_1SelExt( centralWidget() );
77 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ADD_POINT" ) );
78 GroupPoints->TextLabel1->setText( tr( "GEOM_EDGE" ) );
79 GroupPoints->PushButton1->setIcon( image1 );
80 GroupPoints->LineEdit1->setReadOnly( true );
82 QRadioButton* rb1 = new QRadioButton( tr( "GEOM_BY_PARAMETER" ), GroupPoints->Box );
83 QRadioButton* rb2 = new QRadioButton( tr( "GEOM_BY_LENGTH" ), GroupPoints->Box );
85 myIsParameterGr = new QButtonGroup( GroupPoints->Box );
86 myIsParameterGr->addButton( rb1, 0 );
87 myIsParameterGr->addButton( rb2, 1 );
88 rb1->setChecked( true );
90 myValEdt = new SalomeApp_DoubleSpinBox( GroupPoints->Box );
91 initSpinBox( myValEdt, 0., 1., 0.1, "parametric_precision" );
92 myValEdt->setValue( 0.5 );
93 QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->Box );
95 QGridLayout* l = new QGridLayout( GroupPoints->Box );
96 l->setMargin( 0 ); l->setSpacing( 6 );
97 l->addWidget( rb1, 0, 0, 1, 2 );
98 l->addWidget( rb2, 1, 0, 1, 2 );
99 l->addWidget( aLbl1, 2, 0 );
100 l->addWidget( myValEdt, 2, 1 );
102 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
103 layout->setMargin( 0 ); layout->setSpacing( 6 );
104 layout->addWidget( GroupPoints );
106 /***************************************************************/
108 setHelpFileName( "add_point_on_edge_operation_page.html" );
113 //=================================================================================
114 // function : ~RepairGUI_DivideEdgeDlg()
115 // purpose : Destroys the object and frees any allocated resources
116 //=================================================================================
117 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
121 //=================================================================================
124 //=================================================================================
125 void RepairGUI_DivideEdgeDlg::Init()
128 myEditCurrentArgument = GroupPoints->LineEdit1;
130 myObject = GEOM::GEOM_Object::_nil();
133 //myGeomGUI->SetState( 0 );
136 /* signals and slots connections */
137 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
138 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
140 connect( myValEdt, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
142 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
143 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
145 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
146 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
148 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
150 SelectionIntoArgument();
153 //=================================================================================
154 // function : ValueChangedInSpinBox()
155 // purpose : On change value in spin box
156 //=================================================================================
157 void RepairGUI_DivideEdgeDlg::ValueChangedInSpinBox()
162 //=================================================================================
163 // function : displayPreview()
164 // purpose : On display Preview
165 //=================================================================================
166 void RepairGUI_DivideEdgeDlg::displayPreview()
169 if ( myObject->_is_nil() )
174 GEOMBase::GetShape( myObject, aShape, TopAbs_SHAPE );
176 if ( myIndex != -1) {
177 TopTools_IndexedMapOfShape aShapes;
178 TopExp::MapShapes(aShape, aShapes);
179 aShape = aShapes.FindKey(myIndex);
182 if (aShape.ShapeType() == TopAbs_EDGE) {
183 Standard_Real aFP, aLP, aP;
184 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
185 aP = aFP + (aLP - aFP) * myValEdt->value();
186 aPnt = aCurve->Value(aP);
187 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
188 aShape = mkVertex.Shape();
190 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aShape );
191 if ( aPrs != 0 && !aPrs->IsNull() )
192 GEOMBase_Helper::displayPreview( aPrs, false, true );
196 //=================================================================================
197 // function : ClickOnOk()
198 // purpose : Same than click on apply but close this dialog.
199 //=================================================================================
200 void RepairGUI_DivideEdgeDlg::ClickOnOk()
202 setIsApplyAndClose( true );
203 if ( ClickOnApply() )
208 //=================================================================================
209 // function : ClickOnApply()
211 //=================================================================================
212 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
219 myEditCurrentArgument->setText( "" );
220 myObject = GEOM::GEOM_Object::_nil();
229 //=================================================================================
230 // function : SelectionIntoArgument()
231 // purpose : Called when selection as changed or other case
232 // : used only by SelectButtonC1A1 (LineEditC1A1)
233 //=================================================================================
234 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
236 myEditCurrentArgument->setText( "" );
238 myObject = GEOM::GEOM_Object::_nil();
241 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
242 SALOME_ListIO aSelList;
243 aSelMgr->selectedObjects(aSelList);
245 if ( aSelList.Extent() == 1 ) {
246 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
247 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO );
248 if ( !CORBA::is_nil( aSelectedObj ) )
251 QString aName = GEOMBase::GetName( aSelectedObj );
252 if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
254 const int aType = aShape.ShapeType();
255 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
257 GEOM::short_array anIndexes;
259 TColStd_IndexedMapOfInteger aMap;
260 SalomeApp_Application* anApp =
261 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
262 anApp->selectionMgr()->GetIndexes( anIO, aMap );
264 if ( !aMap.IsEmpty() ) // subshape selection
267 myObject = aSelectedObj;
268 myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( myIndex ) );
270 else if ( aType == TopAbs_EDGE ) // single shape selection
273 myObject = aSelectedObj;
274 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
276 else // face, shell, solid or compound was selected, and NOT its subshape.
279 myObject = GEOM::GEOM_Object::_nil();
289 //=================================================================================
290 // function : SetEditCurrentArgument()
292 //=================================================================================
293 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
295 if ( sender() == GroupPoints->PushButton1 ) {
296 GroupPoints->LineEdit1->setFocus();
297 myEditCurrentArgument = GroupPoints->LineEdit1;
299 SelectionIntoArgument();
303 //=================================================================================
304 // function : LineEditReturnPressed()
306 //=================================================================================
307 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
309 if ( sender() == GroupPoints->LineEdit1 ) {
310 myEditCurrentArgument = GroupPoints->LineEdit1;
311 GEOMBase_Skeleton::LineEditReturnPressed();
316 //=================================================================================
317 // function : ActivateThisDialog()
319 //=================================================================================
320 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
322 GEOMBase_Skeleton::ActivateThisDialog();
323 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
324 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
326 // myObject = GEOM::GEOM_Object::_nil();
329 //myGeomGUI->SetState( 0 );
333 //=================================================================================
334 // function : enterEvent()
335 // purpose : Mouse enter onto the dialog to activate it
336 //=================================================================================
337 void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
339 if ( !mainFrame()->GroupConstructors->isEnabled() )
340 ActivateThisDialog();
344 //=================================================================================
345 // function : createOperation
347 //=================================================================================
348 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
350 return getGeomEngine()->GetIHealingOperations( getStudyId() );
353 //=================================================================================
354 // function : isValid
356 //=================================================================================
357 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
359 bool ok = myValEdt->isValid( msg, !IsPreview() );
360 return !myObject->_is_nil() && ok;
363 //=================================================================================
364 // function : execute
366 //=================================================================================
367 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
369 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
370 GEOM::GEOM_Object_var anObj = anOper->DivideEdge( myObject, myIndex, myValEdt->value(), getIsByParameter() );
371 bool aResult = !anObj->_is_nil();
376 QStringList aParameters;
378 aParameters << myValEdt->text();
380 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
382 objects.push_back( anObj._retn() );
388 //=================================================================================
389 // function : getIsByParameter
391 //=================================================================================
392 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
394 return myIsParameterGr->button( 0 )->isChecked();
397 //=================================================================================
398 // function : initSelection
400 //=================================================================================
401 void RepairGUI_DivideEdgeDlg::initSelection()
403 GEOM::GEOM_Object_var aNullGeomObject;
404 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects