Salome HOME
930fb95c44563af25376becc68a4d25519fb4999
[modules/geom.git] / src / RepairGUI / RepairGUI_RemoveExtraEdgesDlg.cxx
1 // 
2 //  This library is distributed in the hope that it will be useful, 
3 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
4 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
5 //  Lesser General Public License for more details. 
6 // 
7 //  You should have received a copy of the GNU Lesser General Public 
8 //  License along with this library; if not, write to the Free Software 
9 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
10 // 
11 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
12 //
13 //
14 //
15 //  File   : RepairGUI_RemoveExtraEdgesDlg.cxx
16 //  Author : Michael Zorin
17 //  Module : GEOM
18 //  $Header: 
19
20 #include "RepairGUI_RemoveExtraEdgesDlg.h"
21
22 #include "SalomeApp_Application.h"
23 #include "LightApp_SelectionMgr.h"
24 #include "SUIT_Session.h"
25
26 #include "GEOMImpl_Types.hxx"
27
28 #include <TColStd_MapOfInteger.hxx>
29
30 #include <qlabel.h>
31
32 using namespace std;
33
34 //=================================================================================
35 // class    : RepairGUI_RemoveExtraEdgesDlg()
36 // purpose  : Constructs a RepairGUI_RemoveExtraEdgesDlg which is a child of 'parent', with the
37 //            name 'name' and widget flags set to 'f'.
38 //            The dialog will by default be modeless, unless you set 'modal' to
39 //            TRUE to construct a modal dialog.
40 //=================================================================================
41 RepairGUI_RemoveExtraEdgesDlg::RepairGUI_RemoveExtraEdgesDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
42                                                              const char* name, bool modal, WFlags fl)
43   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
44                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
45 {
46   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_REMOVE_EXTRA_EDGES")));
47   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
48     
49   setCaption(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
50
51   /***************************************************************/
52   GroupConstructors->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES_TITLE"));
53   RadioButton1->setPixmap(image0);
54   RadioButton2->close(TRUE);
55   RadioButton3->close(TRUE);
56
57   GroupPoints = new DlgRef_1Sel_QTD(this, "GroupPoints");
58   GroupPoints->GroupBox1->setTitle(tr("GEOM_REMOVE_EXTRA_EDGES"));
59   GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE"));
60   GroupPoints->PushButton1->setPixmap(image1);
61   GroupPoints->LineEdit1->setReadOnly( true );
62
63   Layout1->addWidget(GroupPoints, 2, 0);
64   /***************************************************************/
65   
66   setHelpFileName("remove_extra_edges_operation_page.html");
67
68   Init();
69 }
70
71
72 //=================================================================================
73 // function : ~RepairGUI_RemoveExtraEdgesDlg()
74 // purpose  : Destroys the object and frees any allocated resources
75 //=================================================================================
76 RepairGUI_RemoveExtraEdgesDlg::~RepairGUI_RemoveExtraEdgesDlg()
77 {
78 }
79
80
81 //=================================================================================
82 // function : Init()
83 // purpose  :
84 //=================================================================================
85 void RepairGUI_RemoveExtraEdgesDlg::Init()
86 {
87   /* init variables */
88   myEditCurrentArgument = GroupPoints->LineEdit1;
89   
90   myOkObject = false;
91
92   activateSelection();
93   
94   /* signals and slots connections */
95   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
96   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
97
98   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
99   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
100
101   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
102           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
103
104   initName( tr( "REMOVE_EXTRA_EDGES_NEW_OBJ_NAME" ) );
105 }
106
107
108 //=================================================================================
109 // function : ClickOnOk()
110 // purpose  : Same than click on apply but close this dialog.
111 //=================================================================================
112 void RepairGUI_RemoveExtraEdgesDlg::ClickOnOk()
113 {
114   if ( ClickOnApply() )
115     ClickOnCancel();
116 }
117
118 //=================================================================================
119 // function : ClickOnApply()
120 // purpose  :
121 //=================================================================================
122 bool RepairGUI_RemoveExtraEdgesDlg::ClickOnApply()
123 {
124   if ( !onAccept() )
125     return false;
126
127   initName();
128
129   myEditCurrentArgument->setText("");
130   myObject = GEOM::GEOM_Object::_nil();
131   
132   activateSelection();
133
134   return true;
135 }
136
137
138 //=================================================================================
139 // function : SelectionIntoArgument()
140 // purpose  : Called when selection as changed or other case
141 //          : used only by SelectButtonC1A1 (LineEditC1A1)
142 //=================================================================================
143 void RepairGUI_RemoveExtraEdgesDlg::SelectionIntoArgument()
144 {
145   myEditCurrentArgument->setText("");
146   QString aName;
147   
148   if(myEditCurrentArgument == GroupPoints->LineEdit1) {
149     if (IObjectCount() != 1) {
150       if (myEditCurrentArgument == GroupPoints->LineEdit1)
151         myOkObject = false;
152       return;
153     }
154   }
155   
156   // nbSel == 1
157   Standard_Boolean testResult = Standard_False;
158   GEOM::GEOM_Object_ptr aSelectedObject =
159     GEOMBase::ConvertIOinGEOMObject( firstIObject(), testResult );
160
161   if (!testResult)
162     return;
163   
164   if (myEditCurrentArgument == GroupPoints->LineEdit1) {
165     myObject = aSelectedObject;
166     myOkObject = true;
167   }
168
169   myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
170 }
171
172 //=================================================================================
173 // function : SetEditCurrentArgument()
174 // purpose  :
175 //=================================================================================
176 void RepairGUI_RemoveExtraEdgesDlg::SetEditCurrentArgument()
177 {
178   if( sender() == GroupPoints->PushButton1 )
179   {
180     GroupPoints->LineEdit1->setFocus();
181     myEditCurrentArgument = GroupPoints->LineEdit1;
182   }
183   SelectionIntoArgument();
184 }
185
186
187 //=================================================================================
188 // function : LineEditReturnPressed()
189 // purpose  :
190 //=================================================================================
191 void RepairGUI_RemoveExtraEdgesDlg::LineEditReturnPressed()
192 {
193   if( sender() == GroupPoints->LineEdit1 )
194   {
195     myEditCurrentArgument = GroupPoints->LineEdit1;
196     GEOMBase_Skeleton::LineEditReturnPressed();
197   }
198 }
199
200
201 //=================================================================================
202 // function : ActivateThisDialog()
203 // purpose  :
204 //=================================================================================
205 void RepairGUI_RemoveExtraEdgesDlg::ActivateThisDialog()
206 {
207   GEOMBase_Skeleton::ActivateThisDialog();
208   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
209           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
210
211   activateSelection();
212 }
213
214
215 //=================================================================================
216 // function : enterEvent()
217 // purpose  : Mouse enter onto the dialog to activate it
218 //=================================================================================
219 void RepairGUI_RemoveExtraEdgesDlg::enterEvent(QEvent* e)
220 {
221   if ( !GroupConstructors->isEnabled() )
222     ActivateThisDialog();
223 }
224
225
226 //=================================================================================
227 // function : closeEvent()
228 // purpose  :
229 //=================================================================================
230 void RepairGUI_RemoveExtraEdgesDlg::closeEvent(QCloseEvent* e)
231 {
232   GEOMBase_Skeleton::closeEvent( e );
233 }
234
235 //=================================================================================
236 // function : activateSelection
237 // purpose  : activate selection of solids and compounds
238 //=================================================================================
239 void RepairGUI_RemoveExtraEdgesDlg::activateSelection()
240 {
241   TColStd_MapOfInteger aTypes;
242   aTypes.Add( GEOM_SOLID );
243   aTypes.Add( GEOM_COMPOUND );
244   globalSelection( aTypes );
245 }
246
247 //=================================================================================
248 // function : createOperation
249 // purpose  :
250 //=================================================================================
251 GEOM::GEOM_IOperations_ptr RepairGUI_RemoveExtraEdgesDlg::createOperation()
252 {
253   return getGeomEngine()->GetIBlocksOperations( getStudyId() );
254 }
255
256 //=================================================================================
257 // function : isValid
258 // purpose  :
259 //=================================================================================
260 bool RepairGUI_RemoveExtraEdgesDlg::isValid( QString& msg )
261 {
262   return myOkObject;
263 }
264
265 //=================================================================================
266 // function : execute
267 // purpose  :
268 //=================================================================================
269 bool RepairGUI_RemoveExtraEdgesDlg::execute( ObjectList& objects )
270 {
271   GEOM::GEOM_Object_var anObj;
272   
273   anObj = GEOM::GEOM_IBlocksOperations::_narrow(getOperation())->RemoveExtraEdges(myObject);
274   
275   if ( !anObj->_is_nil() )
276     objects.push_back( anObj._retn() );
277
278   return true;
279 }