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 "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
38 #include <TopoDS_Edge.hxx>
39 #include <BRepBuilderAPI_MakeWire.hxx>
40 #include <BRepOffsetAPI_MakePipe.hxx>
41 #if OCC_VERSION_MAJOR >= 5
42 #include <BRepAlgo.hxx>
44 #include <BRepAlgoAPI.hxx>
47 #include "GEOMImpl_Types.hxx"
49 #include "utilities.h"
51 //=================================================================================
52 // class : GenerationGUI_PipeDlg()
53 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
59 const char* name, bool modal, WFlags fl)
60 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
64 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
66 setCaption(tr("GEOM_PIPE_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle(tr("GEOM_PIPE"));
70 RadioButton1->setPixmap(image0);
71 RadioButton2->close(TRUE);
72 RadioButton3->close(TRUE);
74 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
75 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
76 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
77 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
78 GroupPoints->PushButton1->setPixmap(image1);
79 GroupPoints->PushButton2->setPixmap(image1);
80 GroupPoints->LineEdit1->setReadOnly( true );
81 GroupPoints->LineEdit2->setReadOnly( true );
83 Layout1->addWidget(GroupPoints, 2, 0);
84 /***************************************************************/
86 setHelpFileName("pipe_creation.htm");
93 //=================================================================================
94 // function : ~GenerationGUI_PipeDlg()
95 // purpose : Destroys the object and frees any allocated resources
96 //=================================================================================
97 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
99 /* no need to delete child widgets, Qt does it all for us */
103 //=================================================================================
106 //=================================================================================
107 void GenerationGUI_PipeDlg::Init()
110 myEditCurrentArgument = GroupPoints->LineEdit1;
111 GroupPoints->LineEdit1->setReadOnly( true );
112 GroupPoints->LineEdit2->setReadOnly( true );
114 myOkBase = myOkPath = false;
116 /* signals and slots connections */
117 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
118 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
120 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
123 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
124 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
126 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
127 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
129 initName(tr("GEOM_PIPE"));
131 globalSelection( GEOM_ALLSHAPES );
135 //=================================================================================
136 // function : ClickOnOk()
138 //=================================================================================
139 void GenerationGUI_PipeDlg::ClickOnOk()
141 if ( ClickOnApply() )
146 //=================================================================================
147 // function : ClickOnAply()
149 //=================================================================================
150 bool GenerationGUI_PipeDlg::ClickOnApply()
160 //=================================================================================
161 // function : SelectionIntoArgument()
162 // purpose : Called when selection has changed
163 //=================================================================================
164 void GenerationGUI_PipeDlg::SelectionIntoArgument()
167 myEditCurrentArgument->setText("");
169 if(IObjectCount() != 1) {
170 if(myEditCurrentArgument == GroupPoints->LineEdit1)
172 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
178 Standard_Boolean testResult = Standard_False;
179 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), 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;
199 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
202 if(!GEOMBase::GetShape(aSelectedObject, S) ||
203 !(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) )
206 myPath = aSelectedObject;
209 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
215 //=================================================================================
216 // function : SetEditCurrentArgument()
218 //=================================================================================
219 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
221 QPushButton* send = (QPushButton*)sender();
223 if(send == GroupPoints->PushButton1) {
224 GroupPoints->LineEdit1->setFocus();
225 myEditCurrentArgument = GroupPoints->LineEdit1;
227 else if(send == GroupPoints->PushButton2) {
228 GroupPoints->LineEdit2->setFocus();
229 myEditCurrentArgument = GroupPoints->LineEdit2;
231 SelectionIntoArgument();
235 //=================================================================================
236 // function : LineEditReturnPressed()
238 //=================================================================================
239 void GenerationGUI_PipeDlg::LineEditReturnPressed()
241 QLineEdit* send = (QLineEdit*)sender();
242 if(send == GroupPoints->LineEdit1 ||
243 send == GroupPoints->LineEdit2)
245 myEditCurrentArgument = send;
246 GEOMBase_Skeleton::LineEditReturnPressed();
251 //=================================================================================
252 // function : enterEvent()
253 // purpose : when mouse enter onto the QWidget
254 //=================================================================================
255 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
257 if ( !GroupConstructors->isEnabled() )
258 ActivateThisDialog();
262 //=================================================================================
263 // function : ActivateThisDialog()
265 //=================================================================================
266 void GenerationGUI_PipeDlg::ActivateThisDialog()
268 GEOMBase_Skeleton::ActivateThisDialog();
269 globalSelection( GEOM_ALLSHAPES );
270 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
271 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
276 //=================================================================================
277 // function : createOperation
279 //=================================================================================
280 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
282 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
285 //=================================================================================
286 // function : isValid
288 //=================================================================================
289 bool GenerationGUI_PipeDlg::isValid( QString& )
291 return myOkBase && myOkPath;
294 //=================================================================================
295 // function : execute
297 //=================================================================================
298 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
300 GEOM::GEOM_Object_var anObj;
302 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
303 getOperation() )->MakePipe( myBase, myPath );
305 if ( !anObj->_is_nil() )
306 objects.push_back( anObj._retn() );