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
30 #include "GenerationGUI_PipeDlg.h"
32 #include <TopoDS_Edge.hxx>
33 #include <BRepBuilderAPI_MakeWire.hxx>
34 #include <BRepOffsetAPI_MakePipe.hxx>
35 #if OCC_VERSION_MAJOR >= 5
36 #include <BRepAlgo.hxx>
38 #include <BRepAlgoAPI.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(QWidget* parent, const char* name, GenerationGUI* theGenerationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
49 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
51 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
52 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
54 setCaption(tr("GEOM_PIPE_TITLE"));
56 /***************************************************************/
57 GroupConstructors->setTitle(tr("GEOM_PIPE"));
58 RadioButton1->setPixmap(image0);
59 RadioButton2->close(TRUE);
60 RadioButton3->close(TRUE);
62 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
63 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
64 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
65 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
66 GroupPoints->PushButton1->setPixmap(image1);
67 GroupPoints->PushButton2->setPixmap(image1);
69 Layout1->addWidget(GroupPoints, 1, 0);
70 /***************************************************************/
73 myGenerationGUI = theGenerationGUI;
78 //=================================================================================
79 // function : ~GenerationGUI_PipeDlg()
80 // purpose : Destroys the object and frees any allocated resources
81 //=================================================================================
82 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
84 /* no need to delete child widgets, Qt does it all for us */
88 //=================================================================================
91 //=================================================================================
92 void GenerationGUI_PipeDlg::Init()
95 myEditCurrentArgument = GroupPoints->LineEdit1;
97 myOkShape1 = myOkShape2 = false;
99 /* signals and slots connections */
100 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
101 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
103 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
104 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
106 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
107 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
109 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
111 /* displays Dialog */
119 //=================================================================================
120 // function : ClickOnOk()
122 //=================================================================================
123 void GenerationGUI_PipeDlg::ClickOnOk()
125 this->ClickOnApply();
131 //=================================================================================
132 // function : ClickOnAply()
134 //=================================================================================
135 void GenerationGUI_PipeDlg::ClickOnApply()
137 QAD_Application::getDesktop()->putInfo(tr(""));
138 if (mySimulationTopoDs.IsNull())
140 myGeomBase->EraseSimulationShape();
141 mySimulationTopoDs.Nullify();
143 if(myOkShape1 && myOkShape2)
144 myGenerationGUI->MakePipeAndDisplay(myGeomShape2 ,myGeomShape1);
150 //=================================================================================
151 // function : SelectionIntoArgument()
152 // purpose : Called when selection has changed
153 //=================================================================================
154 void GenerationGUI_PipeDlg::SelectionIntoArgument()
156 myGeomBase->EraseSimulationShape();
157 mySimulationTopoDs.Nullify();
158 myEditCurrentArgument->setText("");
159 QString aString = ""; /* name of selection */
161 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
163 if(myEditCurrentArgument == GroupPoints->LineEdit1)
165 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
172 Standard_Boolean testResult;
173 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
174 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
177 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
179 if(S.ShapeType() != TopAbs_COMPSOLID && S.ShapeType() != TopAbs_COMPOUND && S.ShapeType() != TopAbs_SOLID && S.ShapeType() != TopAbs_SHAPE) {
180 myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
183 myEditCurrentArgument->setText(aString);
188 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
190 if(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE ) {
191 myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
194 myEditCurrentArgument->setText(aString);
200 if(myOkShape1 && myOkShape2)
201 this->MakePipeSimulationAndDisplay();
206 //=================================================================================
207 // function : SetEditCurrentArgument()
209 //=================================================================================
210 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
212 QPushButton* send = (QPushButton*)sender();
214 if(send == GroupPoints->PushButton1) {
215 GroupPoints->LineEdit1->setFocus();
216 myEditCurrentArgument = GroupPoints->LineEdit1;
218 else if(send == GroupPoints->PushButton2) {
219 GroupPoints->LineEdit2->setFocus();
220 myEditCurrentArgument = GroupPoints->LineEdit2;
222 this->SelectionIntoArgument();
228 //=================================================================================
229 // function : LineEditReturnPressed()
231 //=================================================================================
232 void GenerationGUI_PipeDlg::LineEditReturnPressed()
234 QLineEdit* send = (QLineEdit*)sender();
235 if(send == GroupPoints->LineEdit1)
236 myEditCurrentArgument = GroupPoints->LineEdit1;
237 else if (send == GroupPoints->LineEdit2)
238 myEditCurrentArgument = GroupPoints->LineEdit2;
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())
255 this->ActivateThisDialog();
260 //=================================================================================
261 // function : ActivateThisDialog()
263 //=================================================================================
264 void GenerationGUI_PipeDlg::ActivateThisDialog()
266 GEOMBase_Skeleton::ActivateThisDialog();
267 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
268 if(!mySimulationTopoDs.IsNull())
269 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
274 //=================================================================================
275 // function : MakeMirrorSimulationAndDisplay()
276 // purpose : S1 is a shape and S2 a mirror.
277 //=================================================================================
278 void GenerationGUI_PipeDlg::MakePipeSimulationAndDisplay()
280 myGeomBase->EraseSimulationShape();
281 mySimulationTopoDs.Nullify();
286 if(myShape2.ShapeType() == TopAbs_WIRE)
287 aWire = TopoDS::Wire(myShape2);
288 else if(myShape2.ShapeType() == TopAbs_EDGE) {
289 TopoDS_Edge aEdge = TopoDS::Edge(myShape2);
290 aWire = BRepBuilderAPI_MakeWire(aEdge);
293 TopoDS_Shape tds = BRepOffsetAPI_MakePipe(aWire,myShape1);
294 #if OCC_VERSION_MAJOR >= 5
295 if(BRepAlgo::IsValid(tds))
297 if(BRepAlgoAPI::IsValid(tds))
301 mySimulationTopoDs = tds;
302 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
305 catch(Standard_Failure) {
306 MESSAGE("Exception catched in MakePipeSimulationAndDisplay");