]> SALOME platform Git repositories - modules/geom.git/blob - src/BuildGUI/BuildGUI_SolidDlg.cxx
Salome HOME
IMPs 21188, 21053, 21064
[modules/geom.git] / src / BuildGUI / BuildGUI_SolidDlg.cxx
1 //  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : BuildGUI_SolidDlg.cxx
24 // Author : Damien COQUERET, Open CASCADE S.A.S.
25
26 #include "BuildGUI_SolidDlg.h"
27
28 #include <DlgRef.h>
29 #include <GeometryGUI.h>
30 #include <GEOMBase.h>
31
32 #include <GEOMImpl_Types.hxx>
33
34 #include <SUIT_ResourceMgr.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39
40 #include <TColStd_MapOfInteger.hxx>
41
42 //=================================================================================
43 // class    : BuildGUI_SolidDlg()
44 // purpose  : Constructs a BuildGUI_SolidDlg which is a child of 'parent', with the
45 //            name 'name' and widget flags set to 'f'.
46 //            The dialog will by default be modeless, unless you set 'modal' to
47 //            TRUE to construct a modal dialog.
48 //=================================================================================
49 BuildGUI_SolidDlg::BuildGUI_SolidDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
50   : GEOMBase_Skeleton( theGeometryGUI, parent )
51 {
52   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_SOLID" ) ) );
53   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
54
55   setWindowTitle( tr( "GEOM_SOLID_TITLE" ) );
56
57   /***************************************************************/
58   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_SOLID" ) );
59   mainFrame()->RadioButton1->setIcon( image0 );
60   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton2->close();
62   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
63   mainFrame()->RadioButton3->close();
64
65   GroupSolid = new DlgRef_1Sel1Check( centralWidget() );
66
67   GroupSolid->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
68   GroupSolid->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
69   GroupSolid->CheckButton1->setText( tr( "GEOM_CREATE_SINGLE_SOLID" ) );
70   GroupSolid->PushButton1->setIcon( image1 );
71   GroupSolid->LineEdit1->setReadOnly( true );
72
73   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
74   layout->setMargin( 0 ); layout->setSpacing( 6 );
75   layout->addWidget( GroupSolid );
76   /***************************************************************/
77
78   setHelpFileName("create_solid_page.html");
79
80   /* Initialisations */
81   Init();
82 }
83
84
85 //=================================================================================
86 // function : ~BuildGUI_SolidDlg()
87 // purpose  : Destroys the object and frees any allocated resources
88 //=================================================================================
89 BuildGUI_SolidDlg::~BuildGUI_SolidDlg()
90 {
91   // no need to delete child widgets, Qt does it all for us
92 }
93
94
95 //=================================================================================
96 // function : Init()
97 // purpose  :
98 //=================================================================================
99 void BuildGUI_SolidDlg::Init()
100 {
101   /* init variables */
102   myEditCurrentArgument = GroupSolid->LineEdit1;
103   GroupSolid->LineEdit1->setReadOnly( true );
104   GroupSolid->CheckButton1->setChecked( true );
105
106   myShells.clear();
107
108   //globalSelection( GEOM_SHELL );
109   TColStd_MapOfInteger aMap;
110   aMap.Add( GEOM_SHELL );
111   aMap.Add( GEOM_COMPOUNDFILTER );
112   QList<int> aSubShapes;
113   aSubShapes.append( GEOM_SHELL );
114   globalSelection( aMap, aSubShapes );
115
116   /* signals and slots connections */
117   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
118   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
119
120   connect( GroupSolid->PushButton1,  SIGNAL( clicked() ),       this, SLOT( SetEditCurrentArgument() ) );
121   connect( GroupSolid->CheckButton1, SIGNAL( toggled( bool ) ), this, SLOT( EnableNameField( bool ) ) );
122
123   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
124            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
125
126   initName( tr( "GEOM_SOLID" ) );
127   SelectionIntoArgument();
128 }
129
130
131 //=================================================================================
132 // function : ClickOnOk()
133 // purpose  :
134 //=================================================================================
135 void BuildGUI_SolidDlg::ClickOnOk()
136 {
137   setIsApplyAndClose( true );
138   if ( ClickOnApply() )
139     ClickOnCancel();
140 }
141
142 //=================================================================================
143 // function : ClickOnApply()
144 // purpose  :
145 //=================================================================================
146 bool BuildGUI_SolidDlg::ClickOnApply()
147 {
148   if ( !onAccept() )
149     return false;
150
151   initName();
152   return true;
153 }
154
155
156 //=================================================================================
157 // function : SelectionIntoArgument()
158 // purpose  : Called when selection as changed or other case
159 //=================================================================================
160 void BuildGUI_SolidDlg::SelectionIntoArgument()
161 {
162   myEditCurrentArgument->setText( "" );
163
164   //myShells = getSelected( TopAbs_SHELL, -1 );
165   QList<TopAbs_ShapeEnum> types;
166   types << TopAbs_SHELL << TopAbs_COMPOUND;
167   myShells = getSelected( types, -1 );
168
169   if ( !myShells.isEmpty() ) {
170     QString aName = myShells.count() > 1 ? QString( "%1_objects").arg( myShells.count() ) : GEOMBase::GetName( myShells[0].get() );
171     myEditCurrentArgument->setText( aName );
172   }
173 }
174
175 //=================================================================================
176 // function : SetEditCurrentArgument()
177 // purpose  :
178 //=================================================================================
179 void BuildGUI_SolidDlg::SetEditCurrentArgument()
180 {
181   QPushButton* send = (QPushButton*)sender();
182   if ( send != GroupSolid->PushButton1 )
183     return;
184
185   //globalSelection( GEOM_SHELL );
186   TColStd_MapOfInteger aMap;
187   aMap.Add( GEOM_SHELL );
188   aMap.Add( GEOM_COMPOUNDFILTER );
189   QList<int> aSubShapes;
190   aSubShapes.append( GEOM_SHELL );
191   globalSelection( aMap, aSubShapes );
192
193   myEditCurrentArgument = GroupSolid->LineEdit1;
194
195   myEditCurrentArgument->setFocus();
196   SelectionIntoArgument();
197 }
198
199
200 //=================================================================================
201 // function : ActivateThisDialog()
202 // purpose  :
203 //=================================================================================
204 void BuildGUI_SolidDlg::ActivateThisDialog()
205 {
206   GEOMBase_Skeleton::ActivateThisDialog();
207   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
208            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
209
210   //globalSelection( GEOM_SHELL );
211   TColStd_MapOfInteger aMap;
212   aMap.Add( GEOM_SHELL );
213   aMap.Add( GEOM_COMPOUNDFILTER );
214   QList<int> aSubShapes;
215   aSubShapes.append( GEOM_SHELL );
216   globalSelection( aMap, aSubShapes );
217 }
218
219
220 //=================================================================================
221 // function : enterEvent()
222 // purpose  :
223 //=================================================================================
224 void BuildGUI_SolidDlg::enterEvent( QEvent* )
225 {
226   if ( !mainFrame()->GroupConstructors->isEnabled() )
227     ActivateThisDialog();
228 }
229
230
231 //=================================================================================
232 // function :  EnableNameField()
233 // purpose  :
234 //=================================================================================
235 void  BuildGUI_SolidDlg::EnableNameField( bool toEnable )
236 {
237   mainFrame()->GroupBoxName->setEnabled( toEnable );
238 }
239
240 //=================================================================================
241 // function : createOperation
242 // purpose  :
243 //=================================================================================
244 GEOM::GEOM_IOperations_ptr BuildGUI_SolidDlg::createOperation()
245 {
246   return getGeomEngine()->GetIShapesOperations( getStudyId() );
247 }
248
249 //=================================================================================
250 // function : isValid
251 // purpose  :
252 //=================================================================================
253 bool BuildGUI_SolidDlg::isValid (QString& msg)
254 {
255   bool ok = !myShells.isEmpty();
256
257   GEOM::MeasureOpPtr anOp;
258   anOp.take(myGeomGUI->GetGeomGen()->GetIMeasureOperations(getStudyId()));
259
260   for ( int i = 0, n = myShells.count(); i < n && ok; i++ ) {
261     CORBA::String_var aRes = anOp->IsGoodForSolid(myShells[i].get());
262     if (strlen(aRes.in())) {
263       msg = QObject::tr(aRes.in()).arg(GEOMBase::GetName(myShells[i].get()));
264       ok = false;
265     }
266   }
267   return ok;
268 }
269
270 /*
271 //=================================================================================
272 // function : isClosed
273 // purpose  : Check the object 'i' in myShells list is closed or unclosed
274 //=================================================================================
275 bool BuildGUI_SolidDlg::isClosed( GEOM::GEOM_Object_ptr shell )
276 {
277   bool ok = false;
278
279   GEOM::GEOM_IKindOfShape::shape_kind aKind;
280   GEOM::ListOfLong_var anInts;
281   GEOM::ListOfDouble_var aDbls;
282
283   if ( !CORBA::is_nil( shell ) ) {
284     GEOM::MeasureOpPtr anOp;
285     anOp.take( myGeomGUI->GetGeomGen()->GetIMeasureOperations( getStudyId() ) );
286
287     // Detect kind of shape and parameters
288     aKind = anOp->KindOfShape(shell, anInts, aDbls);
289
290     if ( anOp->IsDone() ) {
291       if ( anInts[0] == 1 )
292         ok = true;
293       else if ( anInts[0] == 2 )
294         ok = false;
295     }
296     else {
297       MESSAGE ("KindOfShape Operation is NOT DONE!!!");
298     }
299   }
300   else {
301     MESSAGE ("Shape is NULL!!!");
302   }
303
304   return ok;
305 }
306 */
307
308 //=================================================================================
309 // function : execute
310 // purpose  :
311 //=================================================================================
312 bool BuildGUI_SolidDlg::execute( ObjectList& objects )
313 {
314   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
315
316   if ( GroupSolid->CheckButton1->isChecked() ) {
317     GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
318     objlist->length( myShells.count() );
319     for ( int i = 0; i < myShells.count(); i++ )
320       objlist[i] = myShells[i].copy();
321
322     GEOM::GEOM_Object_var anObj = anOper->MakeSolidShells( objlist.in() );
323
324     if ( !anObj->_is_nil() )
325       objects.push_back( anObj._retn() );
326   }
327   else {
328     for ( int i = 0, n = myShells.count(); i< n; i++ ) {
329       GEOM::GEOM_Object_var anObj = anOper->MakeSolidShell( myShells[ i ].get() );
330
331      if ( !anObj->_is_nil() )
332        objects.push_back( anObj._retn() );
333     }
334   }
335
336   return true;
337 }