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" ) );
152 //=================================================================================
153 // function : ValueChangedInSpinBox()
154 // purpose : On change value in spin box
155 //=================================================================================
156 void RepairGUI_DivideEdgeDlg::ValueChangedInSpinBox()
161 //=================================================================================
162 // function : displayPreview()
163 // purpose : On display Preview
164 //=================================================================================
165 void RepairGUI_DivideEdgeDlg::displayPreview()
168 if ( myObject->_is_nil() )
173 GEOMBase::GetShape( myObject, aShape, TopAbs_SHAPE );
175 if ( myIndex != -1) {
176 TopTools_IndexedMapOfShape aShapes;
177 TopExp::MapShapes(aShape, aShapes);
178 aShape = aShapes.FindKey(myIndex);
181 if (aShape.ShapeType() == TopAbs_EDGE) {
182 Standard_Real aFP, aLP, aP;
183 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
184 aP = aFP + (aLP - aFP) * myValEdt->value();
185 aPnt = aCurve->Value(aP);
186 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
187 aShape = mkVertex.Shape();
189 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aShape );
190 if ( aPrs != 0 && !aPrs->IsNull() )
191 GEOMBase_Helper::displayPreview( aPrs, false, true );
195 //=================================================================================
196 // function : ClickOnOk()
197 // purpose : Same than click on apply but close this dialog.
198 //=================================================================================
199 void RepairGUI_DivideEdgeDlg::ClickOnOk()
201 if ( ClickOnApply() )
206 //=================================================================================
207 // function : ClickOnApply()
209 //=================================================================================
210 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
217 myEditCurrentArgument->setText( "" );
218 myObject = GEOM::GEOM_Object::_nil();
227 //=================================================================================
228 // function : SelectionIntoArgument()
229 // purpose : Called when selection as changed or other case
230 // : used only by SelectButtonC1A1 (LineEditC1A1)
231 //=================================================================================
232 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
234 myEditCurrentArgument->setText( "" );
236 myObject = GEOM::GEOM_Object::_nil();
239 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
240 SALOME_ListIO aSelList;
241 aSelMgr->selectedObjects(aSelList);
243 if ( aSelList.Extent() == 1 ) {
244 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
245 Standard_Boolean aRes;
246 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
247 if ( !CORBA::is_nil( aSelectedObj ) && aRes )
250 QString aName = GEOMBase::GetName( aSelectedObj );
251 if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
253 const int aType = aShape.ShapeType();
254 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
256 GEOM::short_array anIndexes;
258 TColStd_IndexedMapOfInteger aMap;
259 SalomeApp_Application* anApp =
260 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
261 anApp->selectionMgr()->GetIndexes( anIO, aMap );
263 if ( !aMap.IsEmpty() ) // subshape selection
266 myObject = aSelectedObj;
267 myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( myIndex ) );
269 else if ( aType == TopAbs_EDGE ) // single shape selection
272 myObject = aSelectedObj;
273 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
275 else // face, shell, solid or compound was selected, and NOT its subshape.
278 myObject = GEOM::GEOM_Object::_nil();
288 //=================================================================================
289 // function : SetEditCurrentArgument()
291 //=================================================================================
292 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
294 if ( sender() == GroupPoints->PushButton1 ) {
295 GroupPoints->LineEdit1->setFocus();
296 myEditCurrentArgument = GroupPoints->LineEdit1;
298 SelectionIntoArgument();
302 //=================================================================================
303 // function : LineEditReturnPressed()
305 //=================================================================================
306 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
308 if ( sender() == GroupPoints->LineEdit1 ) {
309 myEditCurrentArgument = GroupPoints->LineEdit1;
310 GEOMBase_Skeleton::LineEditReturnPressed();
315 //=================================================================================
316 // function : ActivateThisDialog()
318 //=================================================================================
319 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
321 GEOMBase_Skeleton::ActivateThisDialog();
322 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
323 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
325 // myObject = GEOM::GEOM_Object::_nil();
328 //myGeomGUI->SetState( 0 );
332 //=================================================================================
333 // function : enterEvent()
334 // purpose : Mouse enter onto the dialog to activate it
335 //=================================================================================
336 void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
338 if ( !mainFrame()->GroupConstructors->isEnabled() )
339 ActivateThisDialog();
343 //=================================================================================
344 // function : createOperation
346 //=================================================================================
347 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
349 return getGeomEngine()->GetIHealingOperations( getStudyId() );
352 //=================================================================================
353 // function : isValid
355 //=================================================================================
356 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
358 bool ok = myValEdt->isValid( msg, !IsPreview() );
359 return !myObject->_is_nil() && ok;
362 //=================================================================================
363 // function : execute
365 //=================================================================================
366 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
368 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
369 GEOM::GEOM_Object_var anObj = anOper->DivideEdge( myObject, myIndex, myValEdt->value(), getIsByParameter() );
370 bool aResult = !anObj->_is_nil();
375 QStringList aParameters;
377 aParameters << myValEdt->text();
379 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
381 objects.push_back( anObj._retn() );
387 //=================================================================================
388 // function : getIsByParameter
390 //=================================================================================
391 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
393 return myIsParameterGr->button( 0 )->isChecked();
396 //=================================================================================
397 // function : initSelection
399 //=================================================================================
400 void RepairGUI_DivideEdgeDlg::initSelection()
402 GEOM::GEOM_Object_var aNullGeomObject;
403 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects