Salome HOME
DCQ : New Architecture
[modules/geom.git] / src / BuildGUI / BuildGUI_WireDlg.cxx
1 //  GEOM GEOMGUI : GUI for Geometry component
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : BuildGUI_WireDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 using namespace std;
30 #include "BuildGUI_WireDlg.h"
31
32 //=================================================================================
33 // class    : BuildGUI_WireDlg()
34 // purpose  : Constructs a BuildGUI_WireDlg which is a child of 'parent', with the 
35 //            name 'name' and widget flags set to 'f'.
36 //            The dialog will by default be modeless, unless you set 'modal' to
37 //            TRUE to construct a modal dialog.
38 //=================================================================================
39 BuildGUI_WireDlg::BuildGUI_WireDlg(QWidget* parent, const char* name, BuildGUI* theBuildGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
40   :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
41 {
42   QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_BUILD_WIRE")));
43   QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
44
45   setCaption(tr("GEOM_WIRE_TITLE"));
46
47   /***************************************************************/
48   GroupConstructors->setTitle(tr("GEOM_WIRE"));
49   RadioButton1->setPixmap(image0);
50   RadioButton2->close(TRUE);
51   RadioButton3->close(TRUE);
52
53   GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
54   GroupPoints->GroupBox1->setTitle(tr("GEOM_WIRE_CONNECT"));
55   GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
56   GroupPoints->PushButton1->setPixmap(image1);
57
58   Layout1->addWidget(GroupPoints, 1, 0);
59   /***************************************************************/
60
61   /* Initialisations */
62   myBuildGUI = theBuildGUI;
63   Init();
64 }
65
66
67 //=================================================================================
68 // function : ~BuildGUI_WireDlg()
69 // purpose  : Destroys the object and frees any allocated resources
70 //=================================================================================
71 BuildGUI_WireDlg::~BuildGUI_WireDlg()
72 {
73   // no need to delete child widgets, Qt does it all for us
74 }
75
76
77 //=================================================================================
78 // function : Init()
79 // purpose  :
80 //=================================================================================
81 void BuildGUI_WireDlg::Init()
82 {
83   /* init variables */
84   myEditCurrentArgument = GroupPoints->LineEdit1;
85   myOkListShapes = false;
86
87   /* signals and slots connections */
88   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
89   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
90   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));  
91   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
92
93   /* displays Dialog */
94   GroupPoints->show();
95   this->show();
96
97   return;
98 }
99
100
101 //=================================================================================
102 // function : ClickOnOk()
103 // purpose  :
104 //=================================================================================
105 void BuildGUI_WireDlg::ClickOnOk()
106 {
107   this->ClickOnApply();
108   ClickOnCancel();
109   return;
110 }
111
112
113 //=================================================================================
114 // function : ClickOnApply()
115 // purpose  :
116 //=================================================================================
117 void BuildGUI_WireDlg::ClickOnApply()
118 {
119   QAD_Application::getDesktop()->putInfo(tr(""));
120   if(myOkListShapes)  
121     myBuildGUI->MakeWireAndDisplay(myListShapes);
122   return;
123 }
124
125
126 //=================================================================================
127 // function : SelectionIntoArgument()
128 // purpose  : Called when selection as changed or other case
129 //=================================================================================
130 void BuildGUI_WireDlg::SelectionIntoArgument()
131 {
132   myEditCurrentArgument->setText("");
133   QString aString = ""; /* name of selection */
134
135   int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
136   if(nbSel < 1) {
137     myOkListShapes = false;
138     return;
139   }
140   
141   myGeomBase->ConvertListOfIOInListOfIOR(mySelection->StoredIObjects(), myListShapes);
142   myEditCurrentArgument->setText(aString);
143   myOkListShapes = true;
144   /* no simulation */
145   return;
146 }
147
148
149 //=================================================================================
150 // function : SetEditCurrentArgument()
151 // purpose  :
152 //=================================================================================
153 void BuildGUI_WireDlg::SetEditCurrentArgument()
154 {
155   GroupPoints->LineEdit1->setFocus();
156   this->SelectionIntoArgument();
157   return;
158 }
159
160
161 //=================================================================================
162 // function : ActivateThisDialog()
163 // purpose  :
164 //=================================================================================
165 void BuildGUI_WireDlg::ActivateThisDialog()
166 {
167   GEOMBase_Skeleton::ActivateThisDialog();
168   connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
169   return;
170 }
171
172
173 //=================================================================================
174 // function : enterEvent()
175 // purpose  :
176 //=================================================================================
177 void BuildGUI_WireDlg::enterEvent(QEvent* e)
178 {
179   if (GroupConstructors->isEnabled())
180     return;
181   this->ActivateThisDialog();
182   return;
183 }