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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : RepairGUI_DivideEdgeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_DivideEdgeDlg.h"
29 #include <GeometryGUI.h>
32 #include <SalomeApp_Application.h>
33 #include <LightApp_SelectionMgr.h>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
37 #include <GEOMImpl_Types.hxx>
40 #include <Geom_Curve.hxx>
43 #include <TopoDS_Edge.hxx>
44 #include <BRep_Tool.hxx>
45 #include <BRepBuilderAPI_MakeVertex.hxx>
46 #include <TColStd_IndexedMapOfInteger.hxx>
48 //=================================================================================
49 // class : RepairGUI_DivideEdgeDlg()
50 // purpose : Constructs a RepairGUI_DivideEdgeDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
57 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
59 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DIVIDE_EDGE" ) ) );
60 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
62 setWindowTitle( tr( "GEOM_DIVIDE_EDGE_TITLE" ) );
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
66 mainFrame()->RadioButton1->setIcon( image0 );
67 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
68 mainFrame()->RadioButton2->close();
69 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
70 mainFrame()->RadioButton3->close();
72 GroupPoints = new DlgRef_1SelExt( centralWidget() );
73 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ADD_POINT" ) );
74 GroupPoints->TextLabel1->setText( tr( "GEOM_EDGE" ) );
75 GroupPoints->PushButton1->setIcon( image1 );
76 GroupPoints->LineEdit1->setReadOnly( true );
78 QRadioButton* rb1 = new QRadioButton( tr( "GEOM_BY_PARAMETER" ), GroupPoints->Box );
79 QRadioButton* rb2 = new QRadioButton( tr( "GEOM_BY_LENGTH" ), GroupPoints->Box );
81 myIsParameterGr = new QButtonGroup( GroupPoints->Box );
82 myIsParameterGr->addButton( rb1, 0 );
83 myIsParameterGr->addButton( rb2, 1 );
84 rb1->setChecked( true );
86 myValEdt = new QDoubleSpinBox( GroupPoints->Box );
87 initSpinBox( myValEdt, 0., 1., 0.1, 3 );
88 myValEdt->setValue( 0.5 );
89 QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->Box );
91 QGridLayout* l = new QGridLayout( GroupPoints->Box );
92 l->setMargin( 0 ); l->setSpacing( 6 );
93 l->addWidget( rb1, 0, 0, 1, 2 );
94 l->addWidget( rb2, 1, 0, 1, 2 );
95 l->addWidget( aLbl1, 2, 0 );
96 l->addWidget( myValEdt, 2, 1 );
98 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
99 layout->setMargin( 0 ); layout->setSpacing( 6 );
100 layout->addWidget( GroupPoints );
102 /***************************************************************/
104 setHelpFileName( "add_point_on_edge_operation_page.html" );
109 //=================================================================================
110 // function : ~RepairGUI_DivideEdgeDlg()
111 // purpose : Destroys the object and frees any allocated resources
112 //=================================================================================
113 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
117 //=================================================================================
120 //=================================================================================
121 void RepairGUI_DivideEdgeDlg::Init()
124 myEditCurrentArgument = GroupPoints->LineEdit1;
126 myObject = GEOM::GEOM_Object::_nil();
128 //myGeomGUI->SetState( 0 );
131 /* signals and slots connections */
132 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
133 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
135 connect( myValEdt, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
137 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
138 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
140 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
141 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
143 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
146 //=================================================================================
147 // function : ValueChangedInSpinBox()
148 // purpose : On change value in spin box
149 //=================================================================================
150 void RepairGUI_DivideEdgeDlg::ValueChangedInSpinBox()
155 //=================================================================================
156 // function : displayPreview()
157 // purpose : On display Preview
158 //=================================================================================
159 void RepairGUI_DivideEdgeDlg::displayPreview()
161 if ( myObject->_is_nil() )
166 if ( GEOMBase::GetShape( myObject, aShape, TopAbs_SHAPE ) ) {
167 if (aShape.ShapeType() == TopAbs_EDGE) {
168 Standard_Real aFP, aLP, aP;
169 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
170 aP = aFP + (aLP - aFP) * myValEdt->value();
171 aPnt = aCurve->Value(aP);
172 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
173 aShape = mkVertex.Shape();
175 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aShape );
176 if ( aPrs != 0 && !aPrs->IsNull() )
177 GEOMBase_Helper::displayPreview( aPrs, false, true );
182 //=================================================================================
183 // function : ClickOnOk()
184 // purpose : Same than click on apply but close this dialog.
185 //=================================================================================
186 void RepairGUI_DivideEdgeDlg::ClickOnOk()
188 if ( ClickOnApply() )
193 //=================================================================================
194 // function : ClickOnApply()
196 //=================================================================================
197 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
204 myEditCurrentArgument->setText( "" );
205 myObject = GEOM::GEOM_Object::_nil();
213 //=================================================================================
214 // function : SelectionIntoArgument()
215 // purpose : Called when selection as changed or other case
216 // : used only by SelectButtonC1A1 (LineEditC1A1)
217 //=================================================================================
218 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
220 myEditCurrentArgument->setText( "" );
222 myObject = GEOM::GEOM_Object::_nil();
224 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
225 SALOME_ListIO aSelList;
226 aSelMgr->selectedObjects(aSelList);
228 if ( aSelList.Extent() == 1 ) {
229 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
230 Standard_Boolean aRes;
231 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
232 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
233 QString aName = GEOMBase::GetName( aSelectedObject );
235 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) ) {
236 const int aType = aShape.ShapeType();
237 if ( aType <= TopAbs_EDGE ) {
238 // edge, wire, face, shell, solid, compound
239 GEOM::short_array anIndexes;
241 TColStd_IndexedMapOfInteger aMap;
242 aSelMgr->GetIndexes( anIO, aMap );
244 if ( aMap.Extent() == 1 ) { // local selection
245 int anIndex = aMap( 1 );
246 myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( anIndex ) );
248 //Find SubShape Object in Father
249 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
250 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
251 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
252 myObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
255 myObject = aFindedObject; // get Object from study
258 else if ( aType == TopAbs_EDGE ) {
259 // single shape selection
260 myObject = aSelectedObject;
261 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
264 // face, shell, solid or compound was selected, and NOT its subshape.
265 myObject = GEOM::GEOM_Object::_nil();
274 //=================================================================================
275 // function : SetEditCurrentArgument()
277 //=================================================================================
278 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
280 if ( sender() == GroupPoints->PushButton1 ) {
281 GroupPoints->LineEdit1->setFocus();
282 myEditCurrentArgument = GroupPoints->LineEdit1;
284 SelectionIntoArgument();
288 //=================================================================================
289 // function : LineEditReturnPressed()
291 //=================================================================================
292 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
294 if ( sender() == GroupPoints->LineEdit1 ) {
295 myEditCurrentArgument = GroupPoints->LineEdit1;
296 GEOMBase_Skeleton::LineEditReturnPressed();
301 //=================================================================================
302 // function : ActivateThisDialog()
304 //=================================================================================
305 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
307 GEOMBase_Skeleton::ActivateThisDialog();
308 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
309 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
311 // myObject = GEOM::GEOM_Object::_nil();
313 //myGeomGUI->SetState( 0 );
317 //=================================================================================
318 // function : enterEvent()
319 // purpose : Mouse enter onto the dialog to activate it
320 //=================================================================================
321 void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
323 if ( !mainFrame()->GroupConstructors->isEnabled() )
324 ActivateThisDialog();
328 //=================================================================================
329 // function : createOperation
331 //=================================================================================
332 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
334 return getGeomEngine()->GetIHealingOperations( getStudyId() );
337 //=================================================================================
338 // function : isValid
340 //=================================================================================
341 bool RepairGUI_DivideEdgeDlg::isValid( QString& )
343 return !myObject->_is_nil();
346 //=================================================================================
347 // function : execute
349 //=================================================================================
350 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
352 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge
353 ( myObject, -1, myValEdt->value(), getIsByParameter() );
354 bool aResult = !anObj->_is_nil();
356 objects.push_back( anObj._retn() );
361 //=================================================================================
362 // function : getIsByParameter
364 //=================================================================================
365 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
367 return myIsParameterGr->button( 0 )->isChecked();
370 //=================================================================================
371 // function : initSelection
373 //=================================================================================
374 void RepairGUI_DivideEdgeDlg::initSelection()
376 GEOM::GEOM_Object_var aNullGeomObject;
377 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects
380 //=================================================================================
381 // function : addSubshapeToStudy
382 // purpose : virtual method to add new SubObjects if local selection
383 //=================================================================================
384 void RepairGUI_DivideEdgeDlg::addSubshapesToStudy()
386 QMap<QString, GEOM::GEOM_Object_var> objMap;
387 objMap[GroupPoints->LineEdit1->text()] = myObject;
389 addSubshapesToFather( objMap );