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 if ( IObjectCount() == 1 ) {
225 Handle(SALOME_InteractiveObject) anIO = firstIObject();
226 Standard_Boolean aRes;
227 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
228 if ( !CORBA::is_nil( aSelectedObject ) && aRes ) {
229 QString aName = GEOMBase::GetName( aSelectedObject );
231 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) ) {
232 const int aType = aShape.ShapeType();
233 if ( aType <= TopAbs_EDGE ) {
234 // edge, wire, face, shell, solid, compound
235 GEOM::short_array anIndexes;
237 TColStd_IndexedMapOfInteger aMap;
238 SalomeApp_Application* anApp =
239 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
240 anApp->selectionMgr()->GetIndexes( anIO, aMap );
242 if ( aMap.Extent() == 1 ) { // local selection
243 int anIndex = aMap( 1 );
244 myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( anIndex ) );
246 //Find SubShape Object in Father
247 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather( aSelectedObject, aName );
248 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
249 GEOM::GEOM_IShapesOperations_var aShapesOp = getGeomEngine()->GetIShapesOperations( getStudyId() );
250 myObject = aShapesOp->GetSubShape( aSelectedObject, anIndex );
253 myObject = aFindedObject; // get Object from study
256 else if ( aType == TopAbs_EDGE ) {
257 // single shape selection
258 myObject = aSelectedObject;
259 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
262 // face, shell, solid or compound was selected, and NOT its subshape.
263 myObject = GEOM::GEOM_Object::_nil();
272 //=================================================================================
273 // function : SetEditCurrentArgument()
275 //=================================================================================
276 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
278 if ( sender() == GroupPoints->PushButton1 ) {
279 GroupPoints->LineEdit1->setFocus();
280 myEditCurrentArgument = GroupPoints->LineEdit1;
282 SelectionIntoArgument();
286 //=================================================================================
287 // function : LineEditReturnPressed()
289 //=================================================================================
290 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
292 if ( sender() == GroupPoints->LineEdit1 ) {
293 myEditCurrentArgument = GroupPoints->LineEdit1;
294 GEOMBase_Skeleton::LineEditReturnPressed();
299 //=================================================================================
300 // function : ActivateThisDialog()
302 //=================================================================================
303 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
305 GEOMBase_Skeleton::ActivateThisDialog();
306 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
307 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
309 // myObject = GEOM::GEOM_Object::_nil();
311 //myGeomGUI->SetState( 0 );
315 //=================================================================================
316 // function : enterEvent()
317 // purpose : Mouse enter onto the dialog to activate it
318 //=================================================================================
319 void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
321 if ( !mainFrame()->GroupConstructors->isEnabled() )
322 ActivateThisDialog();
326 //=================================================================================
327 // function : createOperation
329 //=================================================================================
330 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
332 return getGeomEngine()->GetIHealingOperations( getStudyId() );
335 //=================================================================================
336 // function : isValid
338 //=================================================================================
339 bool RepairGUI_DivideEdgeDlg::isValid( QString& )
341 return !myObject->_is_nil();
344 //=================================================================================
345 // function : execute
347 //=================================================================================
348 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
350 GEOM::GEOM_Object_var anObj = GEOM::GEOM_IHealingOperations::_narrow( getOperation() )->DivideEdge
351 ( myObject, -1, myValEdt->value(), getIsByParameter() );
352 bool aResult = !anObj->_is_nil();
354 objects.push_back( anObj._retn() );
359 //=================================================================================
360 // function : getIsByParameter
362 //=================================================================================
363 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
365 return myIsParameterGr->button( 0 )->isChecked();
368 //=================================================================================
369 // function : initSelection
371 //=================================================================================
372 void RepairGUI_DivideEdgeDlg::initSelection()
374 GEOM::GEOM_Object_var aNullGeomObject;
375 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects
378 //=================================================================================
379 // function : addSubshapeToStudy
380 // purpose : virtual method to add new SubObjects if local selection
381 //=================================================================================
382 void RepairGUI_DivideEdgeDlg::addSubshapesToStudy()
384 QMap<QString, GEOM::GEOM_Object_var> objMap;
385 objMap[GroupPoints->LineEdit1->text()] = myObject;
387 addSubshapesToFather( objMap );