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
24 // File : GenerationGUI_PipeDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "GenerationGUI_PipeDlg.h"
31 #include "GeometryGUI.h"
34 #include "SUIT_ResourceMgr.h"
35 #include "SUIT_Session.h"
36 #include "SalomeApp_Application.h"
37 #include "LightApp_SelectionMgr.h"
39 #include "GEOMImpl_Types.hxx"
41 //=================================================================================
42 // class : GenerationGUI_PipeDlg()
43 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
44 // name 'name' and widget flags set to 'f'.
45 // The dialog will by default be modeless, unless you set 'modal' to
46 // TRUE to construct a modal dialog.
47 //=================================================================================
48 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
49 const char* name, bool modal, Qt::WindowFlags fl)
50 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
52 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
53 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
55 setWindowTitle(tr("GEOM_PIPE_TITLE"));
57 /***************************************************************/
58 GroupConstructors->setTitle(tr("GEOM_PIPE"));
59 RadioButton1->setIcon(image0);
60 RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61 RadioButton2->close();
62 RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63 RadioButton3->close();
65 GroupPoints = new Ui::DlgRef_2Sel_QTD();
66 QWidget* aGroupPointsWidget = new QWidget(this);
67 GroupPoints->setupUi(aGroupPointsWidget);
68 aGroupPointsWidget->setObjectName("GroupPoints");
70 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
72 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
73 GroupPoints->PushButton1->setIcon(image1);
74 GroupPoints->PushButton2->setIcon(image1);
75 GroupPoints->LineEdit1->setReadOnly( true );
76 GroupPoints->LineEdit2->setReadOnly( true );
78 gridLayout1->addWidget(aGroupPointsWidget, 2, 0);
79 /***************************************************************/
81 setHelpFileName("pipe_creation.htm");
88 //=================================================================================
89 // function : ~GenerationGUI_PipeDlg()
90 // purpose : Destroys the object and frees any allocated resources
91 //=================================================================================
92 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
94 /* no need to delete child widgets, Qt does it all for us */
98 //=================================================================================
101 //=================================================================================
102 void GenerationGUI_PipeDlg::Init()
105 myEditCurrentArgument = GroupPoints->LineEdit1;
106 GroupPoints->LineEdit1->setReadOnly( true );
107 GroupPoints->LineEdit2->setReadOnly( true );
109 myOkBase = myOkPath = false;
111 /* signals and slots connections */
112 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
113 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
115 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
116 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
118 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
119 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
121 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
122 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
124 initName(tr("GEOM_PIPE").toLatin1().constData());
126 globalSelection( GEOM_ALLSHAPES );
130 //=================================================================================
131 // function : ClickOnOk()
133 //=================================================================================
134 void GenerationGUI_PipeDlg::ClickOnOk()
136 if ( ClickOnApply() )
141 //=================================================================================
142 // function : ClickOnAply()
144 //=================================================================================
145 bool GenerationGUI_PipeDlg::ClickOnApply()
155 //=================================================================================
156 // function : SelectionIntoArgument()
157 // purpose : Called when selection has changed
158 //=================================================================================
159 void GenerationGUI_PipeDlg::SelectionIntoArgument()
162 myEditCurrentArgument->setText("");
164 if(IObjectCount() != 1) {
165 if(myEditCurrentArgument == GroupPoints->LineEdit1)
167 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
173 Standard_Boolean testResult = Standard_False;
174 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
181 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
184 if(!GEOMBase::GetShape(aSelectedObject, S) ||
185 S.ShapeType() == TopAbs_COMPSOLID ||
186 S.ShapeType() == TopAbs_COMPOUND ||
187 S.ShapeType() == TopAbs_SOLID ||
188 S.ShapeType() == TopAbs_SHAPE)
191 myBase = aSelectedObject;
194 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
197 if(!GEOMBase::GetShape(aSelectedObject, S) ||
198 !(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) )
201 myPath = aSelectedObject;
204 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
210 //=================================================================================
211 // function : SetEditCurrentArgument()
213 //=================================================================================
214 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
216 QPushButton* send = (QPushButton*)sender();
218 if(send == GroupPoints->PushButton1) {
219 GroupPoints->LineEdit1->setFocus();
220 myEditCurrentArgument = GroupPoints->LineEdit1;
222 else if(send == GroupPoints->PushButton2) {
223 GroupPoints->LineEdit2->setFocus();
224 myEditCurrentArgument = GroupPoints->LineEdit2;
226 SelectionIntoArgument();
230 //=================================================================================
231 // function : LineEditReturnPressed()
233 //=================================================================================
234 void GenerationGUI_PipeDlg::LineEditReturnPressed()
236 QLineEdit* send = (QLineEdit*)sender();
237 if(send == GroupPoints->LineEdit1 ||
238 send == GroupPoints->LineEdit2)
240 myEditCurrentArgument = send;
241 GEOMBase_Skeleton::LineEditReturnPressed();
246 //=================================================================================
247 // function : enterEvent()
248 // purpose : when mouse enter onto the QWidget
249 //=================================================================================
250 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
252 if ( !GroupConstructors->isEnabled() )
253 ActivateThisDialog();
257 //=================================================================================
258 // function : ActivateThisDialog()
260 //=================================================================================
261 void GenerationGUI_PipeDlg::ActivateThisDialog()
263 GEOMBase_Skeleton::ActivateThisDialog();
264 globalSelection( GEOM_ALLSHAPES );
265 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
266 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
271 //=================================================================================
272 // function : createOperation
274 //=================================================================================
275 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
277 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
280 //=================================================================================
281 // function : isValid
283 //=================================================================================
284 bool GenerationGUI_PipeDlg::isValid( QString& )
286 return myOkBase && myOkPath;
289 //=================================================================================
290 // function : execute
292 //=================================================================================
293 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
295 GEOM::GEOM_Object_var anObj;
297 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
298 getOperation() )->MakePipe( myBase, myPath );
300 if ( !anObj->_is_nil() )
301 objects.push_back( anObj._retn() );