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 <SalomeApp_DoubleSpinBox.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( GroupPoints->Box );
90 initSpinBox( myValEdt, 0., 1., 0.1, "parametric_precision" );
91 myValEdt->setValue( 0.5 );
92 QLabel* aLbl1 = new QLabel( tr( "GEOM_VALUE" ), GroupPoints->Box );
94 QGridLayout* l = new QGridLayout( GroupPoints->Box );
95 l->setMargin( 0 ); l->setSpacing( 6 );
96 l->addWidget( rb1, 0, 0, 1, 2 );
97 l->addWidget( rb2, 1, 0, 1, 2 );
98 l->addWidget( aLbl1, 2, 0 );
99 l->addWidget( myValEdt, 2, 1 );
101 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
102 layout->setMargin( 0 ); layout->setSpacing( 6 );
103 layout->addWidget( GroupPoints );
105 /***************************************************************/
107 setHelpFileName( "add_point_on_edge_operation_page.html" );
112 //=================================================================================
113 // function : ~RepairGUI_DivideEdgeDlg()
114 // purpose : Destroys the object and frees any allocated resources
115 //=================================================================================
116 RepairGUI_DivideEdgeDlg::~RepairGUI_DivideEdgeDlg()
120 //=================================================================================
123 //=================================================================================
124 void RepairGUI_DivideEdgeDlg::Init()
127 myEditCurrentArgument = GroupPoints->LineEdit1;
129 myObject = GEOM::GEOM_Object::_nil();
132 //myGeomGUI->SetState( 0 );
135 /* signals and slots connections */
136 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
137 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
139 connect( myValEdt, SIGNAL( valueChanged( double ) ), this, SLOT( ValueChangedInSpinBox() ) );
141 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
142 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
144 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
145 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
147 initName( tr( "DEVIDE_EDGE_NEW_OBJECT_NAME" ) );
151 //=================================================================================
152 // function : ValueChangedInSpinBox()
153 // purpose : On change value in spin box
154 //=================================================================================
155 void RepairGUI_DivideEdgeDlg::ValueChangedInSpinBox()
160 //=================================================================================
161 // function : displayPreview()
162 // purpose : On display Preview
163 //=================================================================================
164 void RepairGUI_DivideEdgeDlg::displayPreview()
167 if ( myObject->_is_nil() )
172 GEOMBase::GetShape( myObject, aShape, TopAbs_SHAPE );
174 if ( myIndex != -1) {
175 TopTools_IndexedMapOfShape aShapes;
176 TopExp::MapShapes(aShape, aShapes);
177 aShape = aShapes.FindKey(myIndex);
180 if (aShape.ShapeType() == TopAbs_EDGE) {
181 Standard_Real aFP, aLP, aP;
182 Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(aShape), aFP, aLP);
183 aP = aFP + (aLP - aFP) * myValEdt->value();
184 aPnt = aCurve->Value(aP);
185 BRepBuilderAPI_MakeVertex mkVertex (aPnt);
186 aShape = mkVertex.Shape();
188 SALOME_Prs* aPrs = getDisplayer()->BuildPrs( aShape );
189 if ( aPrs != 0 && !aPrs->IsNull() )
190 GEOMBase_Helper::displayPreview( aPrs, false, true );
194 //=================================================================================
195 // function : ClickOnOk()
196 // purpose : Same than click on apply but close this dialog.
197 //=================================================================================
198 void RepairGUI_DivideEdgeDlg::ClickOnOk()
200 if ( ClickOnApply() )
205 //=================================================================================
206 // function : ClickOnApply()
208 //=================================================================================
209 bool RepairGUI_DivideEdgeDlg::ClickOnApply()
216 myEditCurrentArgument->setText( "" );
217 myObject = GEOM::GEOM_Object::_nil();
226 //=================================================================================
227 // function : SelectionIntoArgument()
228 // purpose : Called when selection as changed or other case
229 // : used only by SelectButtonC1A1 (LineEditC1A1)
230 //=================================================================================
231 void RepairGUI_DivideEdgeDlg::SelectionIntoArgument()
233 myEditCurrentArgument->setText( "" );
235 myObject = GEOM::GEOM_Object::_nil();
238 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
239 SALOME_ListIO aSelList;
240 aSelMgr->selectedObjects(aSelList);
242 if ( aSelList.Extent() == 1 ) {
243 Handle(SALOME_InteractiveObject) anIO = aSelList.First();
244 Standard_Boolean aRes;
245 GEOM::GEOM_Object_var aSelectedObj = GEOMBase::ConvertIOinGEOMObject( anIO, aRes );
246 if ( !CORBA::is_nil( aSelectedObj ) && aRes )
249 QString aName = GEOMBase::GetName( aSelectedObj );
250 if ( GEOMBase::GetShape( aSelectedObj, aShape, TopAbs_SHAPE ) )
252 const int aType = aShape.ShapeType();
253 if ( aType <= TopAbs_EDGE ) // edge, wire, face, shell, solid, compound
255 GEOM::short_array anIndexes;
257 TColStd_IndexedMapOfInteger aMap;
258 SalomeApp_Application* anApp =
259 (SalomeApp_Application*)(SUIT_Session::session()->activeApplication());
260 anApp->selectionMgr()->GetIndexes( anIO, aMap );
262 if ( !aMap.IsEmpty() ) // subshape selection
265 myObject = aSelectedObj;
266 myEditCurrentArgument->setText( aName += QString( ":edge_%1" ).arg( myIndex ) );
268 else if ( aType == TopAbs_EDGE ) // single shape selection
271 myObject = aSelectedObj;
272 myEditCurrentArgument->setText( GEOMBase::GetName( myObject ) );
274 else // face, shell, solid or compound was selected, and NOT its subshape.
277 myObject = GEOM::GEOM_Object::_nil();
287 //=================================================================================
288 // function : SetEditCurrentArgument()
290 //=================================================================================
291 void RepairGUI_DivideEdgeDlg::SetEditCurrentArgument()
293 if ( sender() == GroupPoints->PushButton1 ) {
294 GroupPoints->LineEdit1->setFocus();
295 myEditCurrentArgument = GroupPoints->LineEdit1;
297 SelectionIntoArgument();
301 //=================================================================================
302 // function : LineEditReturnPressed()
304 //=================================================================================
305 void RepairGUI_DivideEdgeDlg::LineEditReturnPressed()
307 if ( sender() == GroupPoints->LineEdit1 ) {
308 myEditCurrentArgument = GroupPoints->LineEdit1;
309 GEOMBase_Skeleton::LineEditReturnPressed();
314 //=================================================================================
315 // function : ActivateThisDialog()
317 //=================================================================================
318 void RepairGUI_DivideEdgeDlg::ActivateThisDialog()
320 GEOMBase_Skeleton::ActivateThisDialog();
321 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
322 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
324 // myObject = GEOM::GEOM_Object::_nil();
327 //myGeomGUI->SetState( 0 );
331 //=================================================================================
332 // function : enterEvent()
333 // purpose : Mouse enter onto the dialog to activate it
334 //=================================================================================
335 void RepairGUI_DivideEdgeDlg::enterEvent( QEvent* )
337 if ( !mainFrame()->GroupConstructors->isEnabled() )
338 ActivateThisDialog();
342 //=================================================================================
343 // function : createOperation
345 //=================================================================================
346 GEOM::GEOM_IOperations_ptr RepairGUI_DivideEdgeDlg::createOperation()
348 return getGeomEngine()->GetIHealingOperations( getStudyId() );
351 //=================================================================================
352 // function : isValid
354 //=================================================================================
355 bool RepairGUI_DivideEdgeDlg::isValid( QString& msg )
357 bool ok = myValEdt->isValid( msg, !IsPreview() );
358 return !myObject->_is_nil() && ok;
361 //=================================================================================
362 // function : execute
364 //=================================================================================
365 bool RepairGUI_DivideEdgeDlg::execute( ObjectList& objects )
367 GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow( getOperation() );
368 GEOM::GEOM_Object_var anObj = anOper->DivideEdge( myObject, myIndex, myValEdt->value(), getIsByParameter() );
369 bool aResult = !anObj->_is_nil();
374 QStringList aParameters;
376 aParameters << myValEdt->text();
378 anObj->SetParameters(aParameters.join(":").toLatin1().constData());
380 objects.push_back( anObj._retn() );
386 //=================================================================================
387 // function : getIsByParameter
389 //=================================================================================
390 bool RepairGUI_DivideEdgeDlg::getIsByParameter() const
392 return myIsParameterGr->button( 0 )->isChecked();
395 //=================================================================================
396 // function : initSelection
398 //=================================================================================
399 void RepairGUI_DivideEdgeDlg::initSelection()
401 GEOM::GEOM_Object_var aNullGeomObject;
402 localSelection( aNullGeomObject, TopAbs_EDGE ); // load local selection on ALL objects