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()
166 if ( myObject->_is_nil() )
171 GEOMBase::GetShape( myObject, aShape, TopAbs_SHAPE );
173 if ( myIndex != -1) {
174 TopTools_IndexedMapOfShape aShapes;
175 TopExp::MapShapes(aShape, aShapes);
176 aShape = aShapes.FindKey(myIndex);
179 if (aShape.ShapeType() == TopAbs_EDGE) {
180 Standard_Real aFP, aLP, aP;
181 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
182 aP = aFP + (aLP - aFP) * myValEdt->value();
183 aPnt = aCurve->Value(aP);
184 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
185 aShape = mkVertex.Shape();
187 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aShape );
188 if ( aPrs != 0 && !aPrs->IsNull() )
189 GEOMBase_Helper::displayPreview( aPrs, false, true );
193 //=================================================================================
194 // function : ClickOnOk()
195 // purpose : Same than click on apply but close this dialog.
196 //=================================================================================
197 void RepairGUI_DivideEdgeDlg::ClickOnOk()
199 if ( ClickOnApply() )
204 //=================================================================================
205 // function : ClickOnApply()
207 //=================================================================================
208 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
215 myEditCurrentArgument->setText( "" );
216 myObject = GEOM::GEOM_Object::_nil();
225 //=================================================================================
226 // function : SelectionIntoArgument()
227 // purpose : Called when selection as changed or other case
228 // : used only by SelectButtonC1A1 (LineEditC1A1)
229 //=================================================================================
230 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
232 myEditCurrentArgument->setText( "" );
234 myObject = GEOM::GEOM_Object::_nil();
237 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
238 SALOME_ListIO aSelList;
239 aSelMgr->selectedObjects(aSelList);
241 if ( aSelList.Extent() == 1 ) {
242 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
243 Standard_Boolean aRes;
244 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
245 if ( !CORBA::is_nil( aSelectedObj ) && aRes )
248 QString aName = GEOMBase::GetName( aSelectedObj );
249 if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
251 const int aType = aShape.ShapeType();
252 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
254 GEOM::short_array anIndexes;
256 TColStd_IndexedMapOfInteger aMap;
257 SalomeApp_Application* anApp =
258 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
259 anApp->selectionMgr()->GetIndexes( anIO, aMap );
261 if ( !aMap.IsEmpty() ) // subshape selection
264 myObject = aSelectedObj;
265 myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( myIndex ) );
267 else if ( aType == TopAbs_EDGE ) // single shape selection
270 myObject = aSelectedObj;
271 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
273 else // face, shell, solid or compound was selected, and NOT its subshape.
276 myObject = GEOM::GEOM_Object::_nil();
286 //=================================================================================
287 // function : SetEditCurrentArgument()
289 //=================================================================================
290 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
292 if ( sender() == GroupPoints->PushButton1 ) {
293 GroupPoints->LineEdit1->setFocus();
294 myEditCurrentArgument = GroupPoints->LineEdit1;
296 SelectionIntoArgument();
300 //=================================================================================
301 // function : LineEditReturnPressed()
303 //=================================================================================
304 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
306 if ( sender() == GroupPoints->LineEdit1 ) {
307 myEditCurrentArgument = GroupPoints->LineEdit1;
308 GEOMBase_Skeleton::LineEditReturnPressed();
313 //=================================================================================
314 // function : ActivateThisDialog()
316 //=================================================================================
317 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
319 GEOMBase_Skeleton::ActivateThisDialog();
320 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
321 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
323 // myObject = GEOM::GEOM_Object::_nil();
326 //myGeomGUI->SetState( 0 );
330 //=================================================================================
331 // function : enterEvent()
332 // purpose : Mouse enter onto the dialog to activate it
333 //=================================================================================
334 void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
336 if ( !mainFrame()->GroupConstructors->isEnabled() )
337 ActivateThisDialog();
341 //=================================================================================
342 // function : createOperation
344 //=================================================================================
345 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
347 return getGeomEngine()->GetIHealingOperations( getStudyId() );
350 //=================================================================================
351 // function : isValid
353 //=================================================================================
354 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
356 bool ok = myValEdt->isValid( msg, !IsPreview() );
357 return !myObject->_is_nil() && ok;
360 //=================================================================================
361 // function : execute
363 //=================================================================================
364 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
366 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
367 GEOM::GEOM_Object_var anObj = anOper->DivideEdge( myObject, myIndex, myValEdt->value(), getIsByParameter() );
368 bool aResult = !anObj->_is_nil();
373 QStringList aParameters;
375 aParameters << myValEdt->text();
377 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
379 objects.push_back( anObj._retn() );
385 //=================================================================================
386 // function : getIsByParameter
388 //=================================================================================
389 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
391 return myIsParameterGr->button( 0 )->isChecked();
394 //=================================================================================
395 // function : initSelection
397 //=================================================================================
398 void RepairGUI_DivideEdgeDlg::initSelection()
400 GEOM::GEOM_Object_var aNullGeomObject;
401 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects