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 <TopoDS_Edge.hxx>
32 #include <BRepBuilderAPI_MakeWire.hxx>
33 #include <BRepOffsetAPI_MakePipe.hxx>
34 #if OCC_VERSION_MAJOR >= 5
35 #include <BRepAlgo.hxx>
37 #include <BRepAlgoAPI.hxx>
40 #include "GEOMImpl_Types.hxx"
42 #include "QAD_Desktop.h"
43 #include "utilities.h"
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(QWidget* parent, const char* name, SALOME_Selection* Sel, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
56 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
58 setCaption(tr("GEOM_PIPE_TITLE"));
60 /***************************************************************/
61 GroupConstructors->setTitle(tr("GEOM_PIPE"));
62 RadioButton1->setPixmap(image0);
63 RadioButton2->close(TRUE);
64 RadioButton3->close(TRUE);
66 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
67 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
68 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
69 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
70 GroupPoints->PushButton1->setPixmap(image1);
71 GroupPoints->PushButton2->setPixmap(image1);
72 GroupPoints->LineEdit1->setReadOnly( true );
73 GroupPoints->LineEdit2->setReadOnly( true );
75 Layout1->addWidget(GroupPoints, 2, 0);
76 /***************************************************************/
83 //=================================================================================
84 // function : ~GenerationGUI_PipeDlg()
85 // purpose : Destroys the object and frees any allocated resources
86 //=================================================================================
87 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
89 /* no need to delete child widgets, Qt does it all for us */
93 //=================================================================================
96 //=================================================================================
97 void GenerationGUI_PipeDlg::Init()
100 myEditCurrentArgument = GroupPoints->LineEdit1;
101 GroupPoints->LineEdit1->setReadOnly( true );
102 GroupPoints->LineEdit2->setReadOnly( true );
104 myOkBase = myOkPath = false;
106 /* signals and slots connections */
107 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
108 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
110 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
111 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
113 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
114 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
116 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
118 initName(tr("GEOM_PIPE"));
122 //=================================================================================
123 // function : ClickOnOk()
125 //=================================================================================
126 void GenerationGUI_PipeDlg::ClickOnOk()
128 if ( ClickOnApply() )
133 //=================================================================================
134 // function : ClickOnAply()
136 //=================================================================================
137 bool GenerationGUI_PipeDlg::ClickOnApply()
147 //=================================================================================
148 // function : SelectionIntoArgument()
149 // purpose : Called when selection has changed
150 //=================================================================================
151 void GenerationGUI_PipeDlg::SelectionIntoArgument()
154 myEditCurrentArgument->setText("");
156 if(mySelection->IObjectCount() != 1) {
157 if(myEditCurrentArgument == GroupPoints->LineEdit1)
159 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
165 Standard_Boolean testResult = Standard_False;
166 GEOM::GEOM_Object_ptr aSelectedObject = GEOMBase::ConvertIOinGEOMObject( mySelection->firstIObject(), testResult );
173 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
176 if(!GEOMBase::GetShape(aSelectedObject, S) ||
177 S.ShapeType() == TopAbs_COMPSOLID ||
178 S.ShapeType() == TopAbs_COMPOUND ||
179 S.ShapeType() == TopAbs_SOLID ||
180 S.ShapeType() == TopAbs_SHAPE)
183 myBase = aSelectedObject;
186 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
189 if(!GEOMBase::GetShape(aSelectedObject, S) ||
190 !(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE) )
193 myPath = aSelectedObject;
196 myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
202 //=================================================================================
203 // function : SetEditCurrentArgument()
205 //=================================================================================
206 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
208 QPushButton* send = (QPushButton*)sender();
210 if(send == GroupPoints->PushButton1) {
211 GroupPoints->LineEdit1->setFocus();
212 myEditCurrentArgument = GroupPoints->LineEdit1;
214 else if(send == GroupPoints->PushButton2) {
215 GroupPoints->LineEdit2->setFocus();
216 myEditCurrentArgument = GroupPoints->LineEdit2;
218 SelectionIntoArgument();
222 //=================================================================================
223 // function : LineEditReturnPressed()
225 //=================================================================================
226 void GenerationGUI_PipeDlg::LineEditReturnPressed()
228 QLineEdit* send = (QLineEdit*)sender();
229 if(send == GroupPoints->LineEdit1 ||
230 send == GroupPoints->LineEdit2)
232 myEditCurrentArgument = send;
233 GEOMBase_Skeleton::LineEditReturnPressed();
238 //=================================================================================
239 // function : enterEvent()
240 // purpose : when mouse enter onto the QWidget
241 //=================================================================================
242 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
244 if ( !GroupConstructors->isEnabled() )
245 ActivateThisDialog();
249 //=================================================================================
250 // function : ActivateThisDialog()
252 //=================================================================================
253 void GenerationGUI_PipeDlg::ActivateThisDialog()
255 GEOMBase_Skeleton::ActivateThisDialog();
256 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
261 //=================================================================================
262 // function : createOperation
264 //=================================================================================
265 GEOM::GEOM_IOperations_ptr GenerationGUI_PipeDlg::createOperation()
267 return getGeomEngine()->GetI3DPrimOperations( getStudyId() );
270 //=================================================================================
271 // function : isValid
273 //=================================================================================
274 bool GenerationGUI_PipeDlg::isValid( QString& )
276 return myOkBase && myOkPath;
279 //=================================================================================
280 // function : execute
282 //=================================================================================
283 bool GenerationGUI_PipeDlg::execute( ObjectList& objects )
285 GEOM::GEOM_Object_var anObj;
287 anObj = GEOM::GEOM_I3DPrimOperations::_narrow(
288 getOperation() )->MakePipe( myBase, myPath );
290 if ( !anObj->_is_nil() )
291 objects.push_back( anObj._retn() );