]> SALOME platform Git repositories - modules/geom.git/blob - src/BasicGUI/BasicGUI_LineDlg.cxx
Salome HOME
NPAL18111: Bad shape build by partition.
[modules/geom.git] / src / BasicGUI / BasicGUI_LineDlg.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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : BasicGUI_LineDlg.cxx
25 //  Author : Lucien PIGNOLONI
26 //  Module : GEOM
27 //  $Header$
28
29 #include "BasicGUI_LineDlg.h"
30
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
35
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS.hxx>
38 #include <TopExp.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
41
42 #include <qlabel.h>
43
44 #include "GEOMImpl_Types.hxx"
45
46 #include "utilities.h"
47
48 using namespace std;
49
50 //=================================================================================
51 // class    : BasicGUI_LineDlg()
52 // purpose  : Constructs a BasicGUI_LineDlg which is a child of 'parent', with the 
53 //            name 'name' and widget flags set to 'f'.
54 //            The dialog will by default be modeless, unless you set 'modal' to
55 //            TRUE to construct a modal dialog.
56 //=================================================================================
57 BasicGUI_LineDlg::BasicGUI_LineDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
58                                    const char* name, bool modal, WFlags fl)
59   :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
60                      WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
61 {
62   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2P")));
63   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_SELECT")));
64   QPixmap image2(SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM",tr("ICON_DLG_LINE_2F")));
65
66   setCaption(tr("GEOM_LINE_TITLE"));
67
68   QGroupBox* aFrame = new QGroupBox( 1, Qt::Horizontal, this );
69   aFrame->setInsideMargin( 0 );
70   aFrame->setFrameStyle( QFrame::NoFrame );
71
72   /***************************************************************/
73   GroupConstructors->setTitle(tr("GEOM_LINE"));
74   RadioButton1->setPixmap(image0);
75   RadioButton2->setPixmap(image2);
76   RadioButton3->close(TRUE);
77
78   GroupPoints = new DlgRef_2Sel_QTD( aFrame, "GroupPoints");
79   GroupPoints->GroupBox1->setTitle(tr("GEOM_POINTS"));
80   GroupPoints->TextLabel1->setText(tr("GEOM_POINT_I").arg("1"));
81   GroupPoints->TextLabel2->setText(tr("GEOM_POINT_I").arg("2"));
82   GroupPoints->PushButton1->setPixmap(image1);
83   GroupPoints->PushButton2->setPixmap(image1);
84   GroupPoints->LineEdit1->setReadOnly( true );
85   GroupPoints->LineEdit2->setReadOnly( true );
86
87   GroupFaces = new DlgRef_2Sel_QTD( aFrame, "GroupFaces");
88   GroupFaces->GroupBox1->setTitle(tr("GEOM_FACES"));
89   GroupFaces->TextLabel1->setText(tr("GEOM_FACE_I").arg("1"));
90   GroupFaces->TextLabel2->setText(tr("GEOM_FACE_I").arg("2"));
91   GroupFaces->PushButton1->setPixmap(image1);
92   GroupFaces->PushButton2->setPixmap(image1);
93   GroupFaces->LineEdit1->setReadOnly( true );
94   GroupFaces->LineEdit2->setReadOnly( true );
95
96   Layout1->addWidget(aFrame, 2, 0);
97   /***************************************************************/
98
99   setHelpFileName("line.htm");
100
101   Init();
102 }
103
104
105 //=================================================================================
106 // function : ~BasicGUI_LineDlg()
107 // purpose  : Destroys the object and frees any allocated resources
108 //=================================================================================
109 BasicGUI_LineDlg::~BasicGUI_LineDlg()
110 {  
111 }
112
113
114 //=================================================================================
115 // function : Init()
116 // purpose  :
117 //=================================================================================
118 void BasicGUI_LineDlg::Init()
119 {
120   /* init variables */
121   myEditCurrentArgument = GroupPoints->LineEdit1;
122
123   myPoint1 = myPoint2 = GEOM::GEOM_Object::_nil();
124
125   // myGeomGUI->SetState( 0 );
126   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
127         
128   /* signals and slots connections */
129   connect(buttonCancel, SIGNAL(clicked()), this, SLOT(ClickOnCancel()));
130   connect(myGeomGUI, SIGNAL(SignalDeactivateActiveDialog()), this, SLOT(DeactivateActiveDialog()));
131   connect(myGeomGUI, SIGNAL(SignalCloseAllDialogs()), this, SLOT(ClickOnCancel()));
132   connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
133
134   connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
135   connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
136
137   connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
138   connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
139   connect(GroupFaces->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
140   connect(GroupFaces->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
141
142   connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
143   connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
144   connect(GroupFaces->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
145   connect(GroupFaces->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
146
147   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
148           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
149   
150   ConstructorsClicked (0);
151   initName( tr("GEOM_LINE") );
152 }
153
154
155 //=================================================================================
156 // function : ClickOnOk()
157 // purpose  :
158 //=================================================================================
159 void BasicGUI_LineDlg::ClickOnOk()
160 {
161   if ( ClickOnApply() )
162     ClickOnCancel();
163 }
164
165 //=======================================================================
166 // function : ClickOnCancel()
167 // purpose  :
168 //=======================================================================
169 void BasicGUI_LineDlg::ClickOnCancel()
170 {
171   GEOMBase_Skeleton::ClickOnCancel();
172 }
173
174 //=================================================================================
175 // function : ClickOnApply()
176 // purpose  :
177 //=================================================================================
178 bool BasicGUI_LineDlg::ClickOnApply()
179 {
180   if ( !onAccept() )
181     return false;
182   GroupPoints->LineEdit1->setText( "" );
183   GroupPoints->LineEdit2->setText( "" );
184   GroupFaces->LineEdit1->setText( "" );
185   GroupFaces->LineEdit2->setText( "" );
186   myPoint1 = myPoint2 = myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
187   myEditCurrentArgument = GroupPoints->LineEdit1;
188   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX ); //Select vertex on all shapes
189   initName();
190   return true;
191 }
192
193 //=================================================================================
194 // function : ConstructorsClicked()
195 // purpose  : Radio button management
196 //=================================================================================
197 void BasicGUI_LineDlg::ConstructorsClicked(int constructorId)
198 {  
199   switch ( constructorId )
200   {
201   case 0:
202     {
203       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
204       myEditCurrentArgument = GroupPoints->LineEdit1;
205       myEditCurrentArgument->setText("");
206       myPoint1 = GEOM::GEOM_Object::_nil();
207       myPoint2 = GEOM::GEOM_Object::_nil();
208       GroupPoints->show();
209       GroupFaces->hide();
210       break;
211     }
212   case 1:
213     {
214       localSelection( GEOM::GEOM_Object::_nil(), TopAbs_FACE );
215       myEditCurrentArgument = GroupFaces->LineEdit1;
216       myEditCurrentArgument->setText("");
217       myFace1 = GEOM::GEOM_Object::_nil();
218       myFace2 = GEOM::GEOM_Object::_nil();
219       GroupPoints->hide();
220       GroupFaces->show();
221       break;
222     }
223    }
224
225   updateGeometry();
226   resize( minimumSize() );
227   SelectionIntoArgument();
228 }
229
230 //=================================================================================
231 // function : SelectionIntoArgument()
232 // purpose  : Called when selection as changed or other case
233 //=================================================================================
234 void BasicGUI_LineDlg::SelectionIntoArgument()
235 {
236   myEditCurrentArgument->setText("");
237
238   if ( IObjectCount() != 1 ) 
239   {
240     if ( myEditCurrentArgument == GroupPoints->LineEdit1 )      myPoint1 = GEOM::GEOM_Object::_nil();
241     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = GEOM::GEOM_Object::_nil();
242     else if ( myEditCurrentArgument == GroupFaces->LineEdit1 ) myFace1 = GEOM::GEOM_Object::_nil();
243     else if ( myEditCurrentArgument == GroupFaces->LineEdit2 ) myFace2 = GEOM::GEOM_Object::_nil();
244     return;
245   }
246
247   // nbSel == 1 
248   Standard_Boolean aRes = Standard_False;
249   GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject( firstIObject(), aRes );
250   if ( !CORBA::is_nil( aSelectedObject ) && aRes )
251   {
252     myEditCurrentArgument->setText( GEOMBase::GetName( aSelectedObject ) );
253     TopoDS_Shape aShape;
254     if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
255       {
256         LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
257         TColStd_IndexedMapOfInteger aMap;
258         aSelMgr->GetIndexes( firstIObject(), aMap );
259         if ( aMap.Extent() == 1 )
260           {
261             GEOM::GEOM_IShapesOperations_var aShapesOp =
262                       getGeomEngine()->GetIShapesOperations( getStudyId() );
263             int anIndex = aMap( 1 );
264             TopTools_IndexedMapOfShape aShapes;
265             TopExp::MapShapes( aShape, aShapes );
266             aShape = aShapes.FindKey( anIndex );
267             aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
268             aSelMgr->clearSelected();
269           }
270       }
271     if      ( myEditCurrentArgument == GroupPoints->LineEdit1 ) myPoint1 = aSelectedObject;
272     else if ( myEditCurrentArgument == GroupPoints->LineEdit2 ) myPoint2 = aSelectedObject;
273     else if ( myEditCurrentArgument == GroupFaces->LineEdit1 )  myFace1 = aSelectedObject;
274     else if ( myEditCurrentArgument == GroupFaces->LineEdit2 )  myFace2 = aSelectedObject;
275   }
276   
277   displayPreview();
278 }
279
280
281 //=================================================================================
282 // function : SetEditCurrentArgument()
283 // purpose  :
284 //=================================================================================
285 void BasicGUI_LineDlg::SetEditCurrentArgument()
286 {
287   QPushButton* send = (QPushButton*)sender();
288   if      ( send == GroupPoints->PushButton1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
289   else if ( send == GroupPoints->PushButton2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
290   else if ( send == GroupFaces->PushButton1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
291   else if ( send == GroupFaces->PushButton2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
292   myEditCurrentArgument->setFocus();
293   SelectionIntoArgument();
294 }
295
296
297 //=================================================================================
298 // function : LineEditReturnPressed()
299 // purpose  :
300 //=================================================================================
301 void BasicGUI_LineDlg::LineEditReturnPressed()
302 {
303   QLineEdit* send = (QLineEdit*)sender();
304   if      ( send == GroupPoints->LineEdit1 ) myEditCurrentArgument = GroupPoints->LineEdit1;
305   else if ( send == GroupPoints->LineEdit2 ) myEditCurrentArgument = GroupPoints->LineEdit2;
306   else if ( send == GroupFaces->LineEdit1 ) myEditCurrentArgument = GroupFaces->LineEdit1;
307   else if ( send == GroupFaces->LineEdit2 ) myEditCurrentArgument = GroupFaces->LineEdit2;
308   else return;
309   GEOMBase_Skeleton::LineEditReturnPressed();
310 }
311
312
313 //=================================================================================
314 // function : ActivateThisDialog()
315 // purpose  :
316 //=================================================================================
317 void BasicGUI_LineDlg::ActivateThisDialog()
318 {
319   GEOMBase_Skeleton::ActivateThisDialog();
320   connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(), 
321           SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
322
323   // myGeomGUI->SetState( 0 );
324   //  globalSelection( GEOM_POINT );
325   localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
326
327   myEditCurrentArgument = GroupPoints->LineEdit1;
328   myEditCurrentArgument->setFocus();
329
330   GroupPoints->LineEdit1->setText( "" );
331   GroupPoints->LineEdit2->setText( "" );
332   GroupFaces->LineEdit1->setText( "" );
333   GroupFaces->LineEdit2->setText( "" );
334   myPoint1 = myPoint2 = myFace1 = myFace2 = GEOM::GEOM_Object::_nil();
335 }
336
337 //=================================================================================
338 // function : DeactivateActiveDialog()
339 // purpose  : public slot to deactivate if active
340 //=================================================================================
341 void BasicGUI_LineDlg::DeactivateActiveDialog()
342 {
343   // myGeomGUI->SetState( -1 );
344   GEOMBase_Skeleton::DeactivateActiveDialog();
345 }
346
347 //=================================================================================
348 // function : enterEvent()
349 // purpose  :
350 //=================================================================================
351 void BasicGUI_LineDlg::enterEvent(QEvent* e)
352 {
353   if ( !GroupConstructors->isEnabled() )
354     ActivateThisDialog();
355 }
356
357 //=================================================================================
358 // function : createOperation
359 // purpose  :
360 //=================================================================================
361 GEOM::GEOM_IOperations_ptr BasicGUI_LineDlg::createOperation()
362 {
363   return myGeomGUI->GetGeomGen()->GetIBasicOperations( getStudyId() );
364 }
365
366 //=================================================================================
367 // function : isValid
368 // purpose  :
369 //=================================================================================
370 bool BasicGUI_LineDlg::isValid( QString& msg )
371 {
372   const int id = getConstructorId();
373   if ( id == 0 )
374     return !myPoint1->_is_nil() && !myPoint2->_is_nil();
375   else if ( id == 1 )
376     return !myFace1->_is_nil() && !myFace2->_is_nil();
377   return false;
378 }
379
380 //=================================================================================
381 // function : execute
382 // purpose  :
383 //=================================================================================
384 bool BasicGUI_LineDlg::execute( ObjectList& objects )
385 {
386   bool res = false;
387   GEOM::GEOM_Object_var anObj;
388   switch ( getConstructorId() )
389     {
390     case 0 :
391       {
392         anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoPnt( myPoint1, myPoint2 );
393         res = true;
394         break;
395       }
396     case 1 :
397       {
398         anObj = GEOM::GEOM_IBasicOperations::_narrow( getOperation() )->MakeLineTwoFaces( myFace1, myFace2 );
399         res = true;
400         break;
401       }
402     }
403   if ( !anObj->_is_nil() )
404     objects.push_back( anObj._retn() );
405
406   return res;
407 }
408
409 //=================================================================================
410 // function : closeEvent
411 // purpose  :
412 //=================================================================================
413 void BasicGUI_LineDlg::closeEvent( QCloseEvent* e )
414 {
415   GEOMBase_Skeleton::closeEvent( e );
416 }
417