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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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(QWidget* parent, const char* name, bool modal, WFlags fl)
59 :GEOMBase_Skeleton(parent, name, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
61 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
62 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
64 setCaption(tr("GEOM_PIPE_TITLE"));
66 /***************************************************************/
67 GroupConstructors->setTitle(tr("GEOM_PIPE"));
68 RadioButton1->setPixmap(image0);
69 RadioButton2->close(TRUE);
70 RadioButton3->close(TRUE);
72 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
73 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
74 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
75 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
76 GroupPoints->PushButton1->setPixmap(image1);
77 GroupPoints->PushButton2->setPixmap(image1);
78 GroupPoints->LineEdit1->setReadOnly( true );
79 GroupPoints->LineEdit2->setReadOnly( true );
81 Layout1->addWidget(GroupPoints, 2, 0);
82 /***************************************************************/
89 //=================================================================================
90 // function : ~GenerationGUI_PipeDlg()
91 // purpose : Destroys the object and frees any allocated resources
92 //=================================================================================
93 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
95 /* no need to delete child widgets, Qt does it all for us */
99 //=================================================================================
102 //=================================================================================
103 void GenerationGUI_PipeDlg::Init()
106 myEditCurrentArgument = GroupPoints->LineEdit1;
107 GroupPoints->LineEdit1->setReadOnly( true );
108 GroupPoints->LineEdit2->setReadOnly( true );
110 myOkBase = myOkPath = false;
112 /* signals and slots connections */
113 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
114 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
116 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
117 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
120 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
122 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
123 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
125 initName(tr("GEOM_PIPE"));
127 globalSelection( GEOM_ALLSHAPES );
131 //=================================================================================
132 // function : ClickOnOk()
134 //=================================================================================
135 void GenerationGUI_PipeDlg::ClickOnOk()
137 if ( ClickOnApply() )
142 //=================================================================================
143 // function : ClickOnAply()
145 //=================================================================================
146 bool GenerationGUI_PipeDlg::ClickOnApply()
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose : Called when selection has changed
159 //=================================================================================
160 void GenerationGUI_PipeDlg::SelectionIntoArgument()
163 myEditCurrentArgument->setText("");
165 if(IObjectCount() != 1) {
166 if(myEditCurrentArgument == GroupPoints->LineEdit1)
168 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
174 Standard_Boolean testResult = Standard_False;
175 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
182 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
185 if(!GEOMBase::GetShape(aSelectedObject, S) ||
186 S.ShapeType() == TopAbs_COMPSOLID ||
187 S.ShapeType() == TopAbs_COMPOUND ||
188 S.ShapeType() == TopAbs_SOLID ||
189 S.ShapeType() == TopAbs_SHAPE)
192 myBase = aSelectedObject;
195 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
198 if(!GEOMBase::GetShape(aSelectedObject, S) ||
199 !(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) )
202 myPath = aSelectedObject;
205 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
211 //=================================================================================
212 // function : SetEditCurrentArgument()
214 //=================================================================================
215 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
217 QPushButton* send = (QPushButton*)sender();
219 if(send == GroupPoints->PushButton1) {
220 GroupPoints->LineEdit1->setFocus();
221 myEditCurrentArgument = GroupPoints->LineEdit1;
223 else if(send == GroupPoints->PushButton2) {
224 GroupPoints->LineEdit2->setFocus();
225 myEditCurrentArgument = GroupPoints->LineEdit2;
227 SelectionIntoArgument();
231 //=================================================================================
232 // function : LineEditReturnPressed()
234 //=================================================================================
235 void GenerationGUI_PipeDlg::LineEditReturnPressed()
237 QLineEdit* send = (QLineEdit*)sender();
238 if(send == GroupPoints->LineEdit1 ||
239 send == GroupPoints->LineEdit2)
241 myEditCurrentArgument = send;
242 GEOMBase_Skeleton::LineEditReturnPressed();
247 //=================================================================================
248 // function : enterEvent()
249 // purpose : when mouse enter onto the QWidget
250 //=================================================================================
251 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
253 if ( !GroupConstructors->isEnabled() )
254 ActivateThisDialog();
258 //=================================================================================
259 // function : ActivateThisDialog()
261 //=================================================================================
262 void GenerationGUI_PipeDlg::ActivateThisDialog()
264 GEOMBase_Skeleton::ActivateThisDialog();
265 globalSelection( GEOM_ALLSHAPES );
266 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
267 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
272 //=================================================================================
273 // function : createOperation
275 //=================================================================================
276 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
278 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
281 //=================================================================================
282 // function : isValid
284 //=================================================================================
285 bool GenerationGUI_PipeDlg::isValid( QString& )
287 return myOkBase && myOkPath;
290 //=================================================================================
291 // function : execute
293 //=================================================================================
294 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
296 GEOM::GEOM_Object_var anObj;
298 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
299 getOperation() )->MakePipe( myBase, myPath );
301 if ( !anObj->_is_nil() )
302 objects.push_back( anObj._retn() );