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 : GenerationGUI_PipeDlg.cxx
23 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "GenerationGUI_PipeDlg.h"
29 #include <GeometryGUI.h>
32 #include <SUIT_ResourceMgr.h>
33 #include <SUIT_Session.h>
34 #include <SalomeApp_Application.h>
35 #include <LightApp_SelectionMgr.h>
37 #include <TopoDS_Shape.hxx>
40 #include <TColStd_IndexedMapOfInteger.hxx>
41 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <GEOMImpl_Types.hxx>
45 //=================================================================================
46 // class : GenerationGUI_PipeDlg()
47 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
53 bool modal, Qt::WindowFlags fl )
54 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
56 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PIPE" ) ) );
57 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
59 setWindowTitle( tr( "GEOM_PIPE_TITLE" ) );
61 /***************************************************************/
62 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PIPE" ) );
63 mainFrame()->RadioButton1->setIcon(image0);
64 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
65 mainFrame()->RadioButton2->close();
66 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
67 mainFrame()->RadioButton3->close();
69 GroupPoints = new DlgRef_2Sel( centralWidget() );
71 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
72 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_OBJECT" ) );
73 GroupPoints->TextLabel2->setText( tr( "GEOM_PATH_OBJECT" ) );
74 GroupPoints->PushButton1->setIcon( image1 );
75 GroupPoints->PushButton2->setIcon( image1 );
76 GroupPoints->LineEdit1->setReadOnly( true );
77 GroupPoints->LineEdit2->setReadOnly( true );
79 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
80 layout->setMargin( 0 ); layout->setSpacing( 6 );
81 layout->addWidget( GroupPoints );
82 /***************************************************************/
84 setHelpFileName( "create_extrusion_alongpath_page.html" );
91 //=================================================================================
92 // function : ~GenerationGUI_PipeDlg()
93 // purpose : Destroys the object and frees any allocated resources
94 //=================================================================================
95 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
97 /* no need to delete child widgets, Qt does it all for us */
101 //=================================================================================
104 //=================================================================================
105 void GenerationGUI_PipeDlg::Init()
108 myEditCurrentArgument = GroupPoints->LineEdit1;
109 GroupPoints->LineEdit1->setReadOnly( true );
110 GroupPoints->LineEdit2->setReadOnly( true );
112 myOkBase = myOkPath = false;
114 /* signals and slots connections */
115 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
116 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
118 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
119 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
121 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
122 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
124 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
125 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
127 initName( tr( "GEOM_PIPE" ) );
129 //globalSelection( GEOM_ALLSHAPES );
133 //=================================================================================
134 // function : ClickOnOk()
136 //=================================================================================
137 void GenerationGUI_PipeDlg::ClickOnOk()
139 if ( ClickOnApply() )
144 //=================================================================================
145 // function : ClickOnAply()
147 //=================================================================================
148 bool GenerationGUI_PipeDlg::ClickOnApply()
158 //=================================================================================
159 // function : SelectionIntoArgument()
160 // purpose : Called when selection has changed
161 //=================================================================================
162 void GenerationGUI_PipeDlg::SelectionIntoArgument()
165 myEditCurrentArgument->setText( "" );
167 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
168 SALOME_ListIO aSelList;
169 aSelMgr->selectedObjects(aSelList);
171 if (aSelList.Extent() != 1) {
172 if (myEditCurrentArgument == GroupPoints->LineEdit1) myOkBase = false;
173 else if (myEditCurrentArgument == GroupPoints->LineEdit2) myOkPath = false;
178 Standard_Boolean testResult = Standard_False;
179 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(aSelList.First(), testResult);
186 if (myEditCurrentArgument == GroupPoints->LineEdit1) {
189 if (!GEOMBase::GetShape(aSelectedObject, S) ||
190 S.ShapeType() == TopAbs_COMPSOLID ||
191 S.ShapeType() == TopAbs_COMPOUND ||
192 S.ShapeType() == TopAbs_SOLID ||
193 S.ShapeType() == TopAbs_SHAPE)
196 myBase = aSelectedObject;
197 myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject));
200 else if (myEditCurrentArgument == GroupPoints->LineEdit2) {
203 if (!GEOMBase::GetShape(aSelectedObject, S))
206 QString aName = GEOMBase::GetName(aSelectedObject);
208 if (testResult && !aSelectedObject->_is_nil() && aSelectedObject != myBase) {
209 TColStd_IndexedMapOfInteger aMap;
210 aSelMgr->GetIndexes(aSelList.First(), aMap);
211 if (aMap.Extent() == 1) {
212 int anIndex = aMap(1);
213 aName.append(":edge_" + QString::number(anIndex));
215 //Find SubShape Object in Father
216 GEOM::GEOM_Object_var aFindedObject = GEOMBase_Helper::findObjectInFather(aSelectedObject, aName);
218 if (aFindedObject == GEOM::GEOM_Object::_nil()) { // Object not found in study
219 GEOM::GEOM_IShapesOperations_var aShapesOp =
220 getGeomEngine()->GetIShapesOperations(getStudyId());
221 myPath = aShapesOp->GetSubShape(aSelectedObject, anIndex);
224 else { // get Object from study
225 myPath = aFindedObject;
231 if (S.ShapeType() != TopAbs_EDGE) {
232 aSelectedObject = GEOM::GEOM_Object::_nil();
236 myPath = aSelectedObject;
239 myEditCurrentArgument->setText(aName);
245 //=================================================================================
246 // function : SetEditCurrentArgument()
248 //=================================================================================
249 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
251 QPushButton* send = (QPushButton*)sender();
254 if ( send == GroupPoints->PushButton1 ) {
255 GroupPoints->LineEdit1->setFocus();
256 globalSelection( GEOM_ALLSHAPES );
257 myEditCurrentArgument = GroupPoints->LineEdit1;
259 else if ( send == GroupPoints->PushButton2 ) {
260 GroupPoints->LineEdit2->setFocus();
261 myEditCurrentArgument = GroupPoints->LineEdit2;
263 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
265 SelectionIntoArgument();
269 //=================================================================================
270 // function : LineEditReturnPressed()
272 //=================================================================================
273 void GenerationGUI_PipeDlg::LineEditReturnPressed()
275 QLineEdit* send = (QLineEdit*)sender();
276 if ( send == GroupPoints->LineEdit1 ||
277 send == GroupPoints->LineEdit2 ) {
278 myEditCurrentArgument = send;
279 GEOMBase_Skeleton::LineEditReturnPressed();
284 //=================================================================================
285 // function : enterEvent()
286 // purpose : when mouse enter onto the QWidget
287 //=================================================================================
288 void GenerationGUI_PipeDlg::enterEvent( QEvent* )
290 if ( !mainFrame()->GroupConstructors->isEnabled() )
291 ActivateThisDialog();
295 //=================================================================================
296 // function : ActivateThisDialog()
298 //=================================================================================
299 void GenerationGUI_PipeDlg::ActivateThisDialog()
301 GEOMBase_Skeleton::ActivateThisDialog();
302 globalSelection( GEOM_ALLSHAPES );
303 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
304 SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
309 //=================================================================================
310 // function : createOperation
312 //=================================================================================
313 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
315 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
318 //=================================================================================
319 // function : isValid
321 //=================================================================================
322 bool GenerationGUI_PipeDlg::isValid( QString& )
324 return myOkBase && myOkPath;
327 //=================================================================================
328 // function : execute
330 //=================================================================================
331 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
333 GEOM::GEOM_Object_var anObj;
335 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
336 getOperation() )->MakePipe( myBase, myPath );
338 if ( !anObj->_is_nil() )
339 objects.push_back( anObj._retn() );
345 //=================================================================================
346 // function : addSubshapeToStudy
347 // purpose : virtual method to add new SubObjects if local selection
348 //=================================================================================
349 void GenerationGUI_PipeDlg::addSubshapesToStudy()
351 QMap<QString, GEOM::GEOM_Object_var> objMap;
353 objMap[GroupPoints->LineEdit2->text()] = myPath;
355 addSubshapesToFather( objMap );