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 if ( IObjectCount() != 1 ) {
168 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
170 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
176 Standard_Boolean testResult = Standard_False;
177 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
184 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
187 if ( !GEOMBase::GetShape( aSelectedObject, S ) ||
188 S.ShapeType() == TopAbs_COMPSOLID ||
189 S.ShapeType() == TopAbs_COMPOUND ||
190 S.ShapeType() == TopAbs_SOLID ||
191 S.ShapeType() == TopAbs_SHAPE )
194 myBase = aSelectedObject;
195 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
198 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
201 if ( !GEOMBase::GetShape( aSelectedObject, S ) )
204 QString aName = GEOMBase::GetName( aSelectedObject );
206 if ( testResult && !aSelectedObject->_is_nil() && aSelectedObject != myBase ) {
207 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
208 TColStd_IndexedMapOfInteger aMap;
210 aSelMgr->GetIndexes( firstIObject(), 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 );
246 //=================================================================================
247 // function : SetEditCurrentArgument()
249 //=================================================================================
250 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
252 QPushButton* send = (QPushButton*)sender();
255 if ( send == GroupPoints->PushButton1 ) {
256 GroupPoints->LineEdit1->setFocus();
257 globalSelection( GEOM_ALLSHAPES );
258 myEditCurrentArgument = GroupPoints->LineEdit1;
260 else if ( send == GroupPoints->PushButton2 ) {
261 GroupPoints->LineEdit2->setFocus();
262 myEditCurrentArgument = GroupPoints->LineEdit2;
264 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_EDGE );
266 SelectionIntoArgument();
270 //=================================================================================
271 // function : LineEditReturnPressed()
273 //=================================================================================
274 void GenerationGUI_PipeDlg::LineEditReturnPressed()
276 QLineEdit* send = (QLineEdit*)sender();
277 if ( send == GroupPoints->LineEdit1 ||
278 send == GroupPoints->LineEdit2 ) {
279 myEditCurrentArgument = send;
280 GEOMBase_Skeleton::LineEditReturnPressed();
285 //=================================================================================
286 // function : enterEvent()
287 // purpose : when mouse enter onto the QWidget
288 //=================================================================================
289 void GenerationGUI_PipeDlg::enterEvent( QEvent* )
291 if ( !mainFrame()->GroupConstructors->isEnabled() )
292 ActivateThisDialog();
296 //=================================================================================
297 // function : ActivateThisDialog()
299 //=================================================================================
300 void GenerationGUI_PipeDlg::ActivateThisDialog()
302 GEOMBase_Skeleton::ActivateThisDialog();
303 globalSelection( GEOM_ALLSHAPES );
304 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
305 SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
310 //=================================================================================
311 // function : createOperation
313 //=================================================================================
314 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
316 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
319 //=================================================================================
320 // function : isValid
322 //=================================================================================
323 bool GenerationGUI_PipeDlg::isValid( QString& )
325 return myOkBase && myOkPath;
328 //=================================================================================
329 // function : execute
331 //=================================================================================
332 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
334 GEOM::GEOM_Object_var anObj;
336 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
337 getOperation() )->MakePipe( myBase, myPath );
339 if ( !anObj->_is_nil() )
340 objects.push_back( anObj._retn() );
346 //=================================================================================
347 // function : addSubshapeToStudy
348 // purpose : virtual method to add new SubObjects if local selection
349 //=================================================================================
350 void GenerationGUI_PipeDlg::addSubshapesToStudy()
352 QMap<QString, GEOM::GEOM_Object_var> objMap;
354 objMap[GroupPoints->LineEdit2->text()] = myPath;
356 addSubshapesToFather( objMap );