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 : GenerationGUI_PipeDlg.cxx
24 // Author : Lucien PIGNOLONI
28 #include "GenerationGUI_PipeDlg.h"
30 #include "SUIT_Desktop.h"
31 #include "SUIT_Session.h"
32 #include "SalomeApp_Application.h"
33 #include "LightApp_SelectionMgr.h"
36 #include <qcheckbox.h>
37 #include <TopoDS_Edge.hxx>
38 #include <TopoDS_Shape.hxx>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <BRepBuilderAPI_MakeWire.hxx>
44 #include <BRepOffsetAPI_MakePipe.hxx>
45 #include <TColStd_IndexedMapOfInteger.hxx>
46 #include <TColStd_MapOfInteger.hxx>
47 #if OCC_VERSION_MAJOR >= 5
48 #include <BRepAlgo.hxx>
50 #include <BRepAlgoAPI.hxx>
53 #include "GEOMImpl_Types.hxx"
55 #include "utilities.h"
57 //=================================================================================
58 // class : GenerationGUI_PipeDlg()
59 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
60 // name 'name' and widget flags set to 'f'.
61 // The dialog will by default be modeless, unless you set 'modal' to
62 // TRUE to construct a modal dialog.
63 //=================================================================================
64 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
65 const char* name, bool modal, WFlags fl)
66 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
67 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
69 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
70 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
71 QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE_BINORMAL")));
73 setCaption(tr("GEOM_PIPE_TITLE"));
75 /***************************************************************/
76 GroupConstructors->setTitle(tr("GEOM_PIPE"));
77 RadioButton1->setPixmap(image0);
78 RadioButton2->setPixmap(image2);
79 RadioButton3->close(TRUE);
81 GroupPoints = new DlgRef_3Sel1Check_QTD(this, "GroupPoints");
82 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
83 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
84 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
85 GroupPoints->TextLabel3->setText(tr("GEOM_VECTOR"));
86 GroupPoints->PushButton1->setPixmap(image1);
87 GroupPoints->PushButton2->setPixmap(image1);
88 GroupPoints->PushButton3->setPixmap(image1);
89 GroupPoints->CheckButton1->setText(tr("GEOM_SELECT_UNPUBLISHED_EDGES"));
91 Layout1->addWidget(GroupPoints, 2, 0);
92 /***************************************************************/
94 setHelpFileName("create_extrusion_alongpath_page.html");
101 //=================================================================================
102 // function : ~GenerationGUI_PipeDlg()
103 // purpose : Destroys the object and frees any allocated resources
104 //=================================================================================
105 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
107 /* no need to delete child widgets, Qt does it all for us */
111 //=================================================================================
114 //=================================================================================
115 void GenerationGUI_PipeDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
119 GroupPoints->LineEdit1->setReadOnly( true );
120 GroupPoints->LineEdit2->setReadOnly( true );
122 myOkBase = myOkPath = myOkVec = false;
124 GroupPoints->CheckButton1->setEnabled(false);
126 /* signals and slots connections */
127 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
128 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
129 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
131 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
132 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
133 connect(GroupPoints->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
135 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
136 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
137 connect(GroupPoints->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
139 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(SelectionTypeButtonClicked()));
141 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
142 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
144 initName(tr("GEOM_PIPE"));
146 // globalSelection( GEOM_ALLSHAPES );
148 GroupPoints->TextLabel3->hide();
149 GroupPoints->PushButton3->hide();
150 GroupPoints->LineEdit3->hide();
151 ConstructorsClicked( 0 );
155 //=================================================================================
156 // function : ConstructorsClicked()
157 // purpose : Radio button management
158 //=================================================================================
159 void GenerationGUI_PipeDlg::ConstructorsClicked( int constructorId )
163 switch (constructorId)
167 GroupPoints->TextLabel3->hide();
168 GroupPoints->PushButton3->hide();
169 GroupPoints->LineEdit3->hide();
174 GroupPoints->TextLabel3->show();
175 GroupPoints->PushButton3->show();
176 GroupPoints->LineEdit3->show();
184 //=================================================================================
185 // function : SelectionBittonClicked()
186 // purpose : Selection type Radio button management
187 //=================================================================================
188 void GenerationGUI_PipeDlg::SelectionTypeButtonClicked()
191 if ( GroupPoints->CheckButton1->isChecked() ) {
192 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
194 TColStd_MapOfInteger aMap;
197 globalSelection(aMap);
199 if(myEditCurrentArgument == GroupPoints->LineEdit2) {
200 myEditCurrentArgument->setText("");
207 //=================================================================================
208 // function : ClickOnOk()
210 //=================================================================================
211 void GenerationGUI_PipeDlg::ClickOnOk()
213 if ( ClickOnApply() )
218 //=================================================================================
219 // function : ClickOnAply()
221 //=================================================================================
222 bool GenerationGUI_PipeDlg::ClickOnApply()
228 if ( getConstructorId() != 1 )
229 ConstructorsClicked( getConstructorId() );
234 //=================================================================================
235 // function : SelectionIntoArgument()
236 // purpose : Called when selection has changed
237 //=================================================================================
238 void GenerationGUI_PipeDlg::SelectionIntoArgument()
241 myEditCurrentArgument->setText("");
243 if(IObjectCount() != 1) {
244 if(myEditCurrentArgument == GroupPoints->LineEdit1)
246 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
248 else if(myEditCurrentArgument == GroupPoints->LineEdit3)
254 Standard_Boolean testResult = Standard_False;
255 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
262 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
265 if(!GEOMBase::GetShape(aSelectedObject, S) ||
266 S.ShapeType() == TopAbs_COMPSOLID ||
267 S.ShapeType() == TopAbs_COMPOUND ||
268 S.ShapeType() == TopAbs_SOLID ||
269 S.ShapeType() == TopAbs_SHAPE)
271 if ( getConstructorId() == 1 &&
272 (S.ShapeType() == TopAbs_SHELL ||
273 S.ShapeType() == TopAbs_VERTEX))
276 myBase = aSelectedObject;
277 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
280 else if(myEditCurrentArgument == GroupPoints->LineEdit2 ||
281 myEditCurrentArgument == GroupPoints->LineEdit3) {
282 myEditCurrentArgument == GroupPoints->LineEdit2 ? myOkPath = false : myOkVec = false;
285 if( !GEOMBase::GetShape(aSelectedObject, S) )
288 QString aName = GEOMBase::GetName( aSelectedObject );
289 if (myEditCurrentArgument == GroupPoints->LineEdit2 && !GroupPoints->CheckButton1->isChecked() ){
290 myPath = aSelectedObject;
295 if ( testResult && !aSelectedObject->_is_nil() && aSelectedObject != myBase)
297 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
298 TColStd_IndexedMapOfInteger aMap;
300 aSelMgr->GetIndexes( firstIObject(), aMap );
301 if ( aMap.Extent() == 1 )
303 int anIndex = aMap( 1 );
304 aName.append( ":edge_" + QString::number( anIndex ) );
306 //Find SubShape Object in Father
307 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
309 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
310 GEOM::GEOM_IShapesOperations_var aShapesOp =
311 getGeomEngine()->GetIShapesOperations( getStudyId() );
312 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
315 else { // get Object from study
316 aSelectedObject = aFindedObject;
322 if (S.ShapeType() != TopAbs_EDGE) {
323 aSelectedObject = GEOM::GEOM_Object::_nil();
328 if (myEditCurrentArgument == GroupPoints->LineEdit2) {
329 myPath = aSelectedObject;
332 else if (myEditCurrentArgument == GroupPoints->LineEdit3) {
333 myVec = aSelectedObject;
338 myEditCurrentArgument->setText( aName );
345 //=================================================================================
346 // function : SetEditCurrentArgument()
348 //=================================================================================
349 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
351 QPushButton* send = (QPushButton*)sender();
354 if(send == GroupPoints->PushButton1) {
355 GroupPoints->LineEdit1->setFocus();
356 globalSelection( GEOM_ALLSHAPES );
357 myEditCurrentArgument = GroupPoints->LineEdit1;
358 GroupPoints->CheckButton1->setEnabled(false);
360 else if(send == GroupPoints->PushButton2) {
361 GroupPoints->LineEdit2->setFocus();
362 myEditCurrentArgument = GroupPoints->LineEdit2;
364 if ( GroupPoints->CheckButton1->isChecked() ) {
365 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
367 TColStd_MapOfInteger aMap;
370 globalSelection(aMap);
372 GroupPoints->CheckButton1->setEnabled(true);
374 else if(send == GroupPoints->PushButton3) {
375 GroupPoints->LineEdit3->setFocus();
376 myEditCurrentArgument = GroupPoints->LineEdit3;
378 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE);
379 GroupPoints->CheckButton1->setEnabled(false);
381 SelectionIntoArgument();
385 //=================================================================================
386 // function : LineEditReturnPressed()
388 //=================================================================================
389 void GenerationGUI_PipeDlg::LineEditReturnPressed()
391 QLineEdit* send = (QLineEdit*)sender();
392 if(send == GroupPoints->LineEdit1 ||
393 send == GroupPoints->LineEdit2 ||
394 send == GroupPoints->LineEdit3)
396 myEditCurrentArgument = send;
397 GEOMBase_Skeleton::LineEditReturnPressed();
400 if (send == GroupPoints->LineEdit2)
401 GroupPoints->CheckButton1->setEnabled(true);
403 GroupPoints->CheckButton1->setEnabled(false);
407 //=================================================================================
408 // function : enterEvent()
409 // purpose : when mouse enter onto the QWidget
410 //=================================================================================
411 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
413 if ( !GroupConstructors->isEnabled() )
414 ActivateThisDialog();
418 //=================================================================================
419 // function : ActivateThisDialog()
421 //=================================================================================
422 void GenerationGUI_PipeDlg::ActivateThisDialog()
424 GEOMBase_Skeleton::ActivateThisDialog();
425 // globalSelection( GEOM_ALLSHAPES );
426 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
427 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
428 ConstructorsClicked(getConstructorId());
432 //=================================================================================
433 // function : createOperation
435 //=================================================================================
436 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
438 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
441 //=================================================================================
442 // function : isValid
444 //=================================================================================
445 bool GenerationGUI_PipeDlg::isValid( QString& )
447 switch ( getConstructorId() ) {
449 return myOkBase && myOkPath;
451 return myOkBase && myOkPath && myOkVec;
455 //=================================================================================
456 // function : execute
458 //=================================================================================
459 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
461 GEOM::GEOM_Object_var anObj;
463 switch ( getConstructorId() ) {
465 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
466 getOperation() )->MakePipe( myBase, myPath );
470 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
471 getOperation() )->MakePipeBiNormalAlongVector( myBase, myPath, myVec );
475 if ( !anObj->_is_nil() )
476 objects.push_back( anObj._retn() );
481 //=================================================================================
482 // function : addSubshapeToStudy
483 // purpose : virtual method to add new SubObjects if local selection
484 //=================================================================================
485 void GenerationGUI_PipeDlg::addSubshapesToStudy()
487 QMap<QString, GEOM::GEOM_Object_var> objMap;
489 objMap[GroupPoints->LineEdit2->text()] = myPath;
491 addSubshapesToFather( objMap );