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 <GEOMImpl_Types.hxx>
39 //=================================================================================
40 // class : GenerationGUI_PipeDlg()
41 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
42 // name 'name' and widget flags set to 'f'.
43 // The dialog will by default be modeless, unless you set 'modal' to
44 // TRUE to construct a modal dialog.
45 //=================================================================================
46 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg( GeometryGUI* theGeometryGUI, QWidget* parent,
47 bool modal, Qt::WindowFlags fl )
48 : GEOMBase_Skeleton( theGeometryGUI, parent, modal, fl )
50 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_PIPE" ) ) );
51 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
53 setWindowTitle( tr( "GEOM_PIPE_TITLE" ) );
55 /***************************************************************/
56 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_PIPE" ) );
57 mainFrame()->RadioButton1->setIcon(image0);
58 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59 mainFrame()->RadioButton2->close();
60 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61 mainFrame()->RadioButton3->close();
63 GroupPoints = new DlgRef_2Sel( centralWidget() );
65 GroupPoints->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66 GroupPoints->TextLabel1->setText( tr( "GEOM_BASE_OBJECT" ) );
67 GroupPoints->TextLabel2->setText( tr( "GEOM_PATH_OBJECT" ) );
68 GroupPoints->PushButton1->setIcon( image1 );
69 GroupPoints->PushButton2->setIcon( image1 );
70 GroupPoints->LineEdit1->setReadOnly( true );
71 GroupPoints->LineEdit2->setReadOnly( true );
73 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74 layout->setMargin( 0 ); layout->setSpacing( 6 );
75 layout->addWidget( GroupPoints );
76 /***************************************************************/
78 setHelpFileName( "pipe_creation.htm" );
85 //=================================================================================
86 // function : ~GenerationGUI_PipeDlg()
87 // purpose : Destroys the object and frees any allocated resources
88 //=================================================================================
89 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
91 /* no need to delete child widgets, Qt does it all for us */
95 //=================================================================================
98 //=================================================================================
99 void GenerationGUI_PipeDlg::Init()
102 myEditCurrentArgument = GroupPoints->LineEdit1;
103 GroupPoints->LineEdit1->setReadOnly( true );
104 GroupPoints->LineEdit2->setReadOnly( true );
106 myOkBase = myOkPath = false;
108 /* signals and slots connections */
109 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
110 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
112 connect( GroupPoints->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
113 connect( GroupPoints->PushButton2, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
115 connect( GroupPoints->LineEdit1, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
116 connect( GroupPoints->LineEdit2, SIGNAL( returnPressed() ), this, SLOT( LineEditReturnPressed() ) );
118 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
119 SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
121 initName( tr( "GEOM_PIPE" ) );
123 globalSelection( GEOM_ALLSHAPES );
127 //=================================================================================
128 // function : ClickOnOk()
130 //=================================================================================
131 void GenerationGUI_PipeDlg::ClickOnOk()
133 if ( ClickOnApply() )
138 //=================================================================================
139 // function : ClickOnAply()
141 //=================================================================================
142 bool GenerationGUI_PipeDlg::ClickOnApply()
152 //=================================================================================
153 // function : SelectionIntoArgument()
154 // purpose : Called when selection has changed
155 //=================================================================================
156 void GenerationGUI_PipeDlg::SelectionIntoArgument()
159 myEditCurrentArgument->setText( "" );
161 if ( IObjectCount() != 1 ) {
162 if ( myEditCurrentArgument == GroupPoints->LineEdit1 )
164 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 )
170 Standard_Boolean testResult = Standard_False;
171 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
178 if ( myEditCurrentArgument == GroupPoints->LineEdit1 ) {
181 if ( !GEOMBase::GetShape( aSelectedObject, S ) ||
182 S.ShapeType() == TopAbs_COMPSOLID ||
183 S.ShapeType() == TopAbs_COMPOUND ||
184 S.ShapeType() == TopAbs_SOLID ||
185 S.ShapeType() == TopAbs_SHAPE )
188 myBase = aSelectedObject;
191 else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) {
194 if ( !GEOMBase::GetShape( aSelectedObject, S ) ||
195 !( S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE ) )
198 myPath = aSelectedObject;
201 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
207 //=================================================================================
208 // function : SetEditCurrentArgument()
210 //=================================================================================
211 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
213 QPushButton* send = (QPushButton*)sender();
215 if ( send == GroupPoints->PushButton1 ) {
216 GroupPoints->LineEdit1->setFocus();
217 myEditCurrentArgument = GroupPoints->LineEdit1;
219 else if ( send == GroupPoints->PushButton2 ) {
220 GroupPoints->LineEdit2->setFocus();
221 myEditCurrentArgument = GroupPoints->LineEdit2;
223 SelectionIntoArgument();
227 //=================================================================================
228 // function : LineEditReturnPressed()
230 //=================================================================================
231 void GenerationGUI_PipeDlg::LineEditReturnPressed()
233 QLineEdit* send = (QLineEdit*)sender();
234 if ( send == GroupPoints->LineEdit1 ||
235 send == GroupPoints->LineEdit2 ) {
236 myEditCurrentArgument = send;
237 GEOMBase_Skeleton::LineEditReturnPressed();
242 //=================================================================================
243 // function : enterEvent()
244 // purpose : when mouse enter onto the QWidget
245 //=================================================================================
246 void GenerationGUI_PipeDlg::enterEvent( QEvent* )
248 if ( !mainFrame()->GroupConstructors->isEnabled() )
249 ActivateThisDialog();
253 //=================================================================================
254 // function : ActivateThisDialog()
256 //=================================================================================
257 void GenerationGUI_PipeDlg::ActivateThisDialog()
259 GEOMBase_Skeleton::ActivateThisDialog();
260 globalSelection( GEOM_ALLSHAPES );
261 connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
262 SIGNAL( currentSelectionChanged() ), this, SLOT(SelectionIntoArgument() ) );
267 //=================================================================================
268 // function : createOperation
270 //=================================================================================
271 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
273 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
276 //=================================================================================
277 // function : isValid
279 //=================================================================================
280 bool GenerationGUI_PipeDlg::isValid( QString& )
282 return myOkBase && myOkPath;
285 //=================================================================================
286 // function : execute
288 //=================================================================================
289 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
291 GEOM::GEOM_Object_var anObj;
293 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
294 getOperation() )->MakePipe( myBase, myPath );
296 if ( !anObj->_is_nil() )
297 objects.push_back( anObj._retn() );