1 // Copyright (C) 2007-2008 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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : RepairGUI_DivideEdgeDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "RepairGUI_DivideEdgeDlg.h"
29 #include <GeometryGUI.h>
31 #include <QtxDoubleSpinBox.h>
33 #include <SalomeApp_Application.h>
34 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
38 #include <GEOMImpl_Types.hxx>
41 #include <Geom_Curve.hxx>
45 #include <TopoDS_Edge.hxx>
46 #include <BRep_Tool.hxx>
47 #include <TopTools_IndexedMapOfShape.hxx>
48 #include <BRepBuilderAPI_MakeVertex.hxx>
49 #include <TColStd_IndexedMapOfInteger.hxx>
51 //=================================================================================
52 // class : RepairGUI_DivideEdgeDlg()
53 // purpose : Constructs a RepairGUI_DivideEdgeDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 RepairGUI_DivideEdgeDlg::RepairGUI_DivideEdgeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
60 : GEOMBase_Skeleton( theGeometryGUI, parent, modal )
62 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_DIVIDE_EDGE" ) ) );
63 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
65 setWindowTitle( tr( "GEOM_DIVIDE_EDGE_TITLE" ) );
67 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle(tr("GEOM_DIVIDE_EDGE_TITLE"));
69 mainFrame()->RadioButton1->setIcon( image0 );
70 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
71 mainFrame()->RadioButton2->close();
72 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
73 mainFrame()->RadioButton3->close();
75 GroupPoints = new DlgRef_1SelExt( centralWidget() );
76 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ADD_POINT" ) );
77 GroupPoints->TextLabel1->setText( tr( "GEOM_EDGE" ) );
78 GroupPoints->PushButton1->setIcon( image1 );
79 GroupPoints->LineEdit1->setReadOnly( true );
81 QRadioButton* rb1 = new QRadioButton( tr( "GEOM_BY_PARAMETER" ), GroupPoints->Box );
82 QRadioButton* rb2 = new QRadioButton( tr( "GEOM_BY_LENGTH" ), GroupPoints->Box );
84 myIsParameterGr = new QButtonGroup( GroupPoints->Box );
85 myIsParameterGr->addButton( rb1, 0 );
86 myIsParameterGr->addButton( rb2, 1 );
87 rb1->setChecked( true );
89 myValEdt = new SalomeApp_DoubleSpinBox( 0., 1., 0.1, 3, 32, GroupPoints->Box );
90 myValEdt->setValue( 0.5 );
91 QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->Box );
93 QGridLayout* l = new QGridLayout( GroupPoints->Box );
94 l->setMargin( 0 ); l->setSpacing( 6 );
95 l->addWidget( rb1, 0, 0, 1, 2 );
96 l->addWidget( rb2, 1, 0, 1, 2 );
97 l->addWidget( aLbl1, 2, 0 );
98 l->addWidget( myValEdt, 2, 1 );
100 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
101 layout->setMargin( 0 ); layout->setSpacing( 6 );
102 layout->addWidget( GroupPoints );
104 /***************************************************************/
106 setHelpFileName( "add_point_on_edge_operation_page.html" );
111 //=================================================================================
112 // function : ~RepairGUI_DivideEdgeDlg()
113 // purpose : Destroys the object and frees any allocated resources
114 //=================================================================================
115 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
119 //=================================================================================
122 //=================================================================================
123 void RepairGUI_DivideEdgeDlg::Init()
126 myEditCurrentArgument = GroupPoints->LineEdit1;
128 myObject = GEOM::GEOM_Object::_nil();
131 //myGeomGUI->SetState( 0 );
134 /* signals and slots connections */
135 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
136 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
138 connect( myValEdt, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
140 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
141 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
143 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
144 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
146 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
150 //=================================================================================
151 // function : ValueChangedInSpinBox()
152 // purpose : On change value in spin box
153 //=================================================================================
154 void RepairGUI_DivideEdgeDlg::ValueChangedInSpinBox()
159 //=================================================================================
160 // function : displayPreview()
161 // purpose : On display Preview
162 //=================================================================================
163 void RepairGUI_DivideEdgeDlg::displayPreview()
165 if ( myObject->_is_nil() )
170 GEOMBase::GetShape( myObject, aShape, TopAbs_SHAPE );
172 if ( myIndex != -1) {
173 TopTools_IndexedMapOfShape aShapes;
174 TopExp::MapShapes(aShape, aShapes);
175 aShape = aShapes.FindKey(myIndex);
178 if (aShape.ShapeType() == TopAbs_EDGE) {
179 Standard_Real aFP, aLP, aP;
180 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
181 aP = aFP + (aLP - aFP) * myValEdt->value();
182 aPnt = aCurve->Value(aP);
183 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
184 aShape = mkVertex.Shape();
186 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aShape );
187 if ( aPrs != 0 && !aPrs->IsNull() )
188 GEOMBase_Helper::displayPreview( aPrs, false, true );
192 //=================================================================================
193 // function : ClickOnOk()
194 // purpose : Same than click on apply but close this dialog.
195 //=================================================================================
196 void RepairGUI_DivideEdgeDlg::ClickOnOk()
198 if ( ClickOnApply() )
203 //=================================================================================
204 // function : ClickOnApply()
206 //=================================================================================
207 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
214 myEditCurrentArgument->setText( "" );
215 myObject = GEOM::GEOM_Object::_nil();
224 //=================================================================================
225 // function : SelectionIntoArgument()
226 // purpose : Called when selection as changed or other case
227 // : used only by SelectButtonC1A1 (LineEditC1A1)
228 //=================================================================================
229 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
231 myEditCurrentArgument->setText( "" );
233 myObject = GEOM::GEOM_Object::_nil();
236 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
237 SALOME_ListIO aSelList;
238 aSelMgr->selectedObjects(aSelList);
240 if ( aSelList.Extent() == 1 ) {
241 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
242 Standard_Boolean aRes;
243 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
244 if ( !CORBA::is_nil( aSelectedObj ) && aRes )
247 QString aName = GEOMBase::GetName( aSelectedObj );
248 if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
250 const int aType = aShape.ShapeType();
251 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
253 GEOM::short_array anIndexes;
255 TColStd_IndexedMapOfInteger aMap;
256 SalomeApp_Application* anApp =
257 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
258 anApp->selectionMgr()->GetIndexes( anIO, aMap );
260 if ( !aMap.IsEmpty() ) // subshape selection
263 myObject = aSelectedObj;
264 myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( myIndex ) );
266 else if ( aType == TopAbs_EDGE ) // single shape selection
269 myObject = aSelectedObj;
270 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
272 else // face, shell, solid or compound was selected, and NOT its subshape.
275 myObject = GEOM::GEOM_Object::_nil();
285 //=================================================================================
286 // function : SetEditCurrentArgument()
288 //=================================================================================
289 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
291 if ( sender() == GroupPoints->PushButton1 ) {
292 GroupPoints->LineEdit1->setFocus();
293 myEditCurrentArgument = GroupPoints->LineEdit1;
295 SelectionIntoArgument();
299 //=================================================================================
300 // function : LineEditReturnPressed()
302 //=================================================================================
303 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
305 if ( sender() == GroupPoints->LineEdit1 ) {
306 myEditCurrentArgument = GroupPoints->LineEdit1;
307 GEOMBase_Skeleton::LineEditReturnPressed();
312 //=================================================================================
313 // function : ActivateThisDialog()
315 //=================================================================================
316 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
318 GEOMBase_Skeleton::ActivateThisDialog();
319 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
320 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
322 // myObject = GEOM::GEOM_Object::_nil();
325 //myGeomGUI->SetState( 0 );
329 //=================================================================================
330 // function : enterEvent()
331 // purpose : Mouse enter onto the dialog to activate it
332 //=================================================================================
333 void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
335 if ( !mainFrame()->GroupConstructors->isEnabled() )
336 ActivateThisDialog();
340 //=================================================================================
341 // function : createOperation
343 //=================================================================================
344 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
346 return getGeomEngine()->GetIHealingOperations( getStudyId() );
349 //=================================================================================
350 // function : isValid
352 //=================================================================================
353 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
355 bool ok = myValEdt->isValid( msg, !IsPreview() );
356 return !myObject->_is_nil() && ok;
359 //=================================================================================
360 // function : execute
362 //=================================================================================
363 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
365 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
366 GEOM::GEOM_Object_var anObj = anOper->DivideEdge( myObject, myIndex, myValEdt->value(), getIsByParameter() );
367 bool aResult = !anObj->_is_nil();
372 QStringList aParameters;
374 aParameters << myValEdt->text();
376 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
378 objects.push_back( anObj._retn() );
384 //=================================================================================
385 // function : getIsByParameter
387 //=================================================================================
388 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
390 return myIsParameterGr->button( 0 )->isChecked();
393 //=================================================================================
394 // function : initSelection
396 //=================================================================================
397 void RepairGUI_DivideEdgeDlg::initSelection()
399 GEOM::GEOM_Object_var aNullGeomObject;
400 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects