Salome HOME
updated copyright message
[modules/geom.git] / src / BuildGUI / BuildGUI_CompoundDlg.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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 //  GEOM GEOMGUI : GUI for Geometry component
24 // File   : BuildGUI_CompoundDlg.cxx
25 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 //
27 #include "BuildGUI_CompoundDlg.h"
28
29 #include <DlgRef.h>
30 #include <GeometryGUI.h>
31 #include <GEOMBase.h>
32
33 #include <GEOMImpl_Types.hxx>
34
35 #include <SUIT_ResourceMgr.h>
36 #include <SUIT_Session.h>
37 #include <SalomeApp_Application.h>
38 #include <LightApp_SelectionMgr.h>
39
40 //=================================================================================
41 // class    : BuildGUI_CompoundDlg()
42 // purpose  : Constructs a BuildGUI_CompoundDlg which is a child of 'parent', with the 
43 //            name 'name' and widget flags set to 'f'.
44 //            The dialog will by default be modeless, unless you set 'modal' to
45 //            TRUE to construct a modal dialog.
46 //=================================================================================
47 BuildGUI_CompoundDlg::BuildGUI_CompoundDlg( GeometryGUI* theGeometryGUI, QWidget* parent )
48   : GEOMBase_Skeleton( theGeometryGUI, parent )
49 {
50   QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_BUILD_COMPOUND" ) ) );
51   QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_SELECT" ) ) );
52
53   setWindowTitle( tr( "GEOM_COMPOUND_TITLE" ) );
54
55   /***************************************************************/
56   mainFrame()->GroupConstructors->setTitle( tr( "GEOM_COMPOUND" ) );
57   mainFrame()->RadioButton1->setIcon( image0 );
58   mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
59   mainFrame()->RadioButton2->close();
60   mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
61   mainFrame()->RadioButton3->close();
62
63   GroupShapes = new DlgRef_1Sel( centralWidget() );
64
65   GroupShapes->GroupBox1->setTitle( tr( "GEOM_ARGUMENTS" ) );
66   GroupShapes->TextLabel1->setText( tr( "GEOM_OBJECTS" ) );
67   GroupShapes->PushButton1->setIcon( image1 );
68   GroupShapes->LineEdit1->setReadOnly( true );
69
70   QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
71   layout->setMargin( 0 ); layout->setSpacing( 6 );
72   layout->addWidget( GroupShapes );
73   /***************************************************************/
74
75   setHelpFileName("create_compound_page.html");
76
77   /* Initialisations */
78   Init();
79 }
80
81
82 //=================================================================================
83 // function : ~BuildGUI_CompoundDlg()
84 // purpose  : Destroys the object and frees any allocated resources
85 //=================================================================================
86 BuildGUI_CompoundDlg::~BuildGUI_CompoundDlg()
87 {
88   // no need to delete child widgets, Qt does it all for us
89 }
90
91
92 //=================================================================================
93 // function : Init()
94 // purpose  :
95 //=================================================================================
96 void BuildGUI_CompoundDlg::Init()
97 {
98   /* init variables */
99   myEditCurrentArgument = GroupShapes->LineEdit1;
100   GroupShapes->LineEdit1->setReadOnly( true );
101   
102   myShapes.clear();
103
104   mainFrame()->GroupBoxPublish->show();
105   mainFrame()->CheckBoxPreview->hide();
106
107   /* signals and slots connections */
108   connect( buttonOk(),    SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
109   connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
110   connect( GroupShapes->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
111   connect( ( (SalomeApp_Application*)(SUIT_Session::session()->activeApplication() ) )->selectionMgr(), 
112            SIGNAL(currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
113
114   globalSelection( GEOM_ALLSHAPES );
115
116   initName( tr( "GEOM_COMPOUND" ) );
117   SelectionIntoArgument();
118 }
119
120
121 //=================================================================================
122 // function : ClickOnOk()
123 // purpose  :
124 //=================================================================================
125 void BuildGUI_CompoundDlg::ClickOnOk()
126 {
127   setIsApplyAndClose( true );
128   if ( ClickOnApply() )
129     ClickOnCancel();
130 }
131
132
133 //=================================================================================
134 // function : ClickOnApply()
135 // purpose  :
136 //=================================================================================
137 bool BuildGUI_CompoundDlg::ClickOnApply()
138 {
139   if ( !onAccept() )
140     return false;
141
142   initName();
143   return true;
144 }
145
146
147 //=================================================================================
148 // function : SelectionIntoArgument()
149 // purpose  : Called when selection as changed or other case
150 //=================================================================================
151 void BuildGUI_CompoundDlg::SelectionIntoArgument()
152 {
153   myEditCurrentArgument->setText( "" );
154
155   myShapes = getSelected( TopAbs_SHAPE, -1 );
156
157   if ( !myShapes.isEmpty() ) {
158     QString aName = myShapes.count() > 1 ? QString( "%1_objects").arg( myShapes.count() ) : GEOMBase::GetName( myShapes[0].get() );
159     myEditCurrentArgument->setText( aName );
160   }
161 }
162
163
164 //=================================================================================
165 // function : SetEditCurrentArgument()
166 // purpose  :
167 //=================================================================================
168 void BuildGUI_CompoundDlg::SetEditCurrentArgument()
169 {
170   QPushButton* send = (QPushButton*)sender();
171   if ( send != GroupShapes->PushButton1 )
172     return;
173   
174   myEditCurrentArgument = GroupShapes->LineEdit1;
175   
176   myEditCurrentArgument->setFocus();
177   SelectionIntoArgument();
178 }
179
180
181 //=================================================================================
182 // function : ActivateThisDialog()
183 // purpose  :
184 //=================================================================================
185 void BuildGUI_CompoundDlg::ActivateThisDialog()
186 {
187   GEOMBase_Skeleton::ActivateThisDialog();
188   globalSelection( GEOM_ALLSHAPES );
189   connect( ( (SalomeApp_Application*)( SUIT_Session::session()->activeApplication() ) )->selectionMgr(),
190            SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
191 }
192
193
194 //=================================================================================
195 // function : enterEvent()
196 // purpose  :
197 //=================================================================================
198 void BuildGUI_CompoundDlg::enterEvent(QEvent*)
199 {
200   if ( !mainFrame()->GroupConstructors->isEnabled() )
201     ActivateThisDialog(); 
202 }
203
204 //=================================================================================
205 // function : createOperation
206 // purpose  :
207 //=================================================================================
208 GEOM::GEOM_IOperations_ptr BuildGUI_CompoundDlg::createOperation()
209 {
210   return getGeomEngine()->GetIShapesOperations();
211 }
212
213 //=================================================================================
214 // function : isValid
215 // purpose  :
216 //=================================================================================
217 bool BuildGUI_CompoundDlg::isValid( QString& )
218 {
219   return !myShapes.isEmpty();
220 }
221
222 //=================================================================================
223 // function : execute
224 // purpose  :
225 //=================================================================================
226 bool BuildGUI_CompoundDlg::execute( ObjectList& objects )
227 {
228   GEOM::GEOM_IShapesOperations_var anOper = GEOM::GEOM_IShapesOperations::_narrow( getOperation() );
229
230   GEOM::ListOfGO_var objlist = new GEOM::ListOfGO();
231   objlist->length( myShapes.count() );
232   for ( int i = 0; i < myShapes.count(); i++ )
233     objlist[i] = myShapes[i].copy();
234
235   GEOM::GEOM_Object_var anObj = anOper->MakeCompound( objlist );
236
237   if ( !anObj->_is_nil() )
238     objects.push_back( anObj._retn() );
239
240   return true;
241 }
242
243 //=================================================================================
244 // function : restoreSubShapes
245 // purpose  :
246 //=================================================================================
247 void BuildGUI_CompoundDlg::restoreSubShapes( SALOMEDS::SObject_ptr theSObject )
248 {
249   if ( mainFrame()->CheckBoxRestoreSS->isChecked() ) {
250     // empty list of arguments means that all arguments should be restored
251     getGeomEngine()->RestoreSubShapesSO( theSObject, GEOM::ListOfGO(),
252                                          /*theFindMethod=*/GEOM::FSM_GetInPlace, // ? GEOM::FSM_GetSame
253                                          /*theInheritFirstArg=*/false,
254                                          mainFrame()->CheckBoxAddPrefix->isChecked() );
255   }
256 }
257
258 //=================================================================================
259 // function : getSourceObjects
260 // purpose  : virtual method to get source objects
261 //=================================================================================
262 QList<GEOM::GeomObjPtr> BuildGUI_CompoundDlg::getSourceObjects()
263 {
264   return myShapes;
265 }