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 "utilities.h"
44 //=================================================================================
45 // class : GenerationGUI_PipeDlg()
46 // purpose : Constructs a GenerationGUI_PipeDlg which is a child of 'parent', with the
47 // name 'name' and widget flags set to 'f'.
48 // The dialog will by default be modeless, unless you set 'modal' to
49 // TRUE to construct a modal dialog.
50 //=================================================================================
51 GenerationGUI_PipeDlg::GenerationGUI_PipeDlg(QWidget* parent, const char* name, GenerationGUI* theGenerationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
52 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
54 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_PIPE")));
55 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
57 setCaption(tr("GEOM_PIPE_TITLE"));
59 /***************************************************************/
60 GroupConstructors->setTitle(tr("GEOM_PIPE"));
61 RadioButton1->setPixmap(image0);
62 RadioButton2->close(TRUE);
63 RadioButton3->close(TRUE);
65 GroupPoints = new DlgRef_2Sel_QTD(this, "GroupPoints");
66 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
67 GroupPoints->TextLabel1->setText(tr("GEOM_BASE_OBJECT"));
68 GroupPoints->TextLabel2->setText(tr("GEOM_PATH_OBJECT"));
69 GroupPoints->PushButton1->setPixmap(image1);
70 GroupPoints->PushButton2->setPixmap(image1);
72 Layout1->addWidget(GroupPoints, 1, 0);
73 /***************************************************************/
76 myGenerationGUI = theGenerationGUI;
81 //=================================================================================
82 // function : ~GenerationGUI_PipeDlg()
83 // purpose : Destroys the object and frees any allocated resources
84 //=================================================================================
85 GenerationGUI_PipeDlg::~GenerationGUI_PipeDlg()
87 /* no need to delete child widgets, Qt does it all for us */
91 //=================================================================================
94 //=================================================================================
95 void GenerationGUI_PipeDlg::Init()
98 myEditCurrentArgument = GroupPoints->LineEdit1;
100 myOkShape1 = myOkShape2 = false;
102 /* signals and slots connections */
103 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
104 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
106 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
107 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
109 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
110 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
112 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
114 /* displays Dialog */
122 //=================================================================================
123 // function : ClickOnOk()
125 //=================================================================================
126 void GenerationGUI_PipeDlg::ClickOnOk()
128 this->ClickOnApply();
134 //=================================================================================
135 // function : ClickOnAply()
137 //=================================================================================
138 void GenerationGUI_PipeDlg::ClickOnApply()
140 QAD_Application::getDesktop()->putInfo(tr(""));
141 if (mySimulationTopoDs.IsNull())
143 myGeomBase->EraseSimulationShape();
144 mySimulationTopoDs.Nullify();
146 if(myOkShape1 && myOkShape2)
147 myGenerationGUI->MakePipeAndDisplay(myGeomShape2 ,myGeomShape1);
153 //=================================================================================
154 // function : SelectionIntoArgument()
155 // purpose : Called when selection has changed
156 //=================================================================================
157 void GenerationGUI_PipeDlg::SelectionIntoArgument()
159 myGeomBase->EraseSimulationShape();
160 mySimulationTopoDs.Nullify();
161 myEditCurrentArgument->setText("");
162 QString aString = ""; /* name of selection */
164 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
166 if(myEditCurrentArgument == GroupPoints->LineEdit1)
168 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
175 Standard_Boolean testResult;
176 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
177 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
180 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
182 if(S.ShapeType() != TopAbs_COMPSOLID && S.ShapeType() != TopAbs_COMPOUND && S.ShapeType() != TopAbs_SOLID && S.ShapeType() != TopAbs_SHAPE) {
183 myGeomShape1 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
186 myEditCurrentArgument->setText(aString);
191 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
193 if(S.ShapeType() == TopAbs_WIRE || S.ShapeType() == TopAbs_EDGE ) {
194 myGeomShape2 = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
197 myEditCurrentArgument->setText(aString);
203 if(myOkShape1 && myOkShape2)
204 this->MakePipeSimulationAndDisplay();
209 //=================================================================================
210 // function : SetEditCurrentArgument()
212 //=================================================================================
213 void GenerationGUI_PipeDlg::SetEditCurrentArgument()
215 QPushButton* send = (QPushButton*)sender();
217 if(send == GroupPoints->PushButton1) {
218 GroupPoints->LineEdit1->setFocus();
219 myEditCurrentArgument = GroupPoints->LineEdit1;
221 else if(send == GroupPoints->PushButton2) {
222 GroupPoints->LineEdit2->setFocus();
223 myEditCurrentArgument = GroupPoints->LineEdit2;
225 this->SelectionIntoArgument();
231 //=================================================================================
232 // function : LineEditReturnPressed()
234 //=================================================================================
235 void GenerationGUI_PipeDlg::LineEditReturnPressed()
237 QLineEdit* send = (QLineEdit*)sender();
238 if(send == GroupPoints->LineEdit1)
239 myEditCurrentArgument = GroupPoints->LineEdit1;
240 else if (send == GroupPoints->LineEdit2)
241 myEditCurrentArgument = GroupPoints->LineEdit2;
245 GEOMBase_Skeleton::LineEditReturnPressed();
250 //=================================================================================
251 // function : enterEvent()
252 // purpose : when mouse enter onto the QWidget
253 //=================================================================================
254 void GenerationGUI_PipeDlg::enterEvent(QEvent* e)
256 if (GroupConstructors->isEnabled())
258 this->ActivateThisDialog();
263 //=================================================================================
264 // function : ActivateThisDialog()
266 //=================================================================================
267 void GenerationGUI_PipeDlg::ActivateThisDialog()
269 GEOMBase_Skeleton::ActivateThisDialog();
270 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
271 if(!mySimulationTopoDs.IsNull())
272 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
277 //=================================================================================
278 // function : MakeMirrorSimulationAndDisplay()
279 // purpose : S1 is a shape and S2 a mirror.
280 //=================================================================================
281 void GenerationGUI_PipeDlg::MakePipeSimulationAndDisplay()
283 myGeomBase->EraseSimulationShape();
284 mySimulationTopoDs.Nullify();
289 if(myShape2.ShapeType() == TopAbs_WIRE)
290 aWire = TopoDS::Wire(myShape2);
291 else if(myShape2.ShapeType() == TopAbs_EDGE) {
292 TopoDS_Edge aEdge = TopoDS::Edge(myShape2);
293 aWire = BRepBuilderAPI_MakeWire(aEdge);
296 TopoDS_Shape tds = BRepOffsetAPI_MakePipe(aWire,myShape1);
297 #if OCC_VERSION_MAJOR >= 5
298 if(BRepAlgo::IsValid(tds))
300 if(BRepAlgoAPI::IsValid(tds))
304 mySimulationTopoDs = tds;
305 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
308 catch(Standard_Failure) {
309 MESSAGE("Exception catched in MakePipeSimulationAndDisplay");