Salome HOME
d2608831832cf7e4669f5cf84f96d1b9710133bd
[modules/geom.git] / src / EntityGUI / EntityGUI_SurfFromFaceDlg.cxx
1 // Copyright (C) 2007-2023  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 // GEOM GEOMGUI : GUI for Geometry component
21 // File   : EntityGUI_SurfFromFaceDlg.cxx
22
23 #include "EntityGUI_SurfFromFaceDlg.h"
24 #include <GeometryGUI.h>
25 #include <DlgRef.h>
26 #include <GEOMBase.h>
27
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <SalomeApp_Application.h>
31 #include <LightApp_SelectionMgr.h>
32
33
34 //=================================================================================
35 // class    : EntityGUI_SurfFromFaceDlg
36 // purpose  : 
37 //=================================================================================
38 EntityGUI_SurfFromFaceDlg::EntityGUI_SurfFromFaceDlg
39                                            (GeometryGUI     *theGeometryGUI,
40                                             QWidget         *parent,
41                                             bool             modal,
42                                             Qt::WindowFlags  fl)
43   : GEOMBase_Skeleton (theGeometryGUI, parent, modal, fl),
44     myGroup           (0)
45 {
46   QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SURFACE_FROM_FACE")));
47   QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
48
49   setWindowTitle(tr("GEOM_SURF_FROM_FACE_TITLE"));
50
51   /***************************************************************/
52
53   mainFrame()->GroupConstructors->setTitle(tr("GEOM_SURF_FROM_FACE"));
54   mainFrame()->RadioButton1->setIcon(image0);
55   mainFrame()->RadioButton2->close();
56   mainFrame()->RadioButton3->close();
57
58   // Construct a group.
59   myGroup = new DlgRef_1Sel(centralWidget());
60   myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
61   myGroup->TextLabel1->setText(tr("GEOM_FACE"));
62   myGroup->PushButton1->setIcon(image1);
63   myGroup->LineEdit1->setReadOnly(true);
64
65   QVBoxLayout* layout = new QVBoxLayout(centralWidget());
66   layout->setMargin(0); layout->setSpacing(6);
67   layout->addWidget(myGroup);
68
69   setHelpFileName("create_surface_from_face_page.html");
70
71   Init();
72 }
73
74 //=================================================================================
75 // function : ~EntityGUI_SurfFromFaceDlg()
76 // purpose  : 
77 //=================================================================================
78 EntityGUI_SurfFromFaceDlg::~EntityGUI_SurfFromFaceDlg()
79 {
80 }
81
82 //=================================================================================
83 // function : Init()
84 // purpose  :
85 //=================================================================================
86 void EntityGUI_SurfFromFaceDlg::Init()
87 {
88   initName(tr("GEOM_SURF_FROM_FACE_NAME"));
89   showOnlyPreviewControl();
90
91   /* signals and slots connections */
92   connect(myGroup->PushButton1, SIGNAL(clicked()),
93           this,                 SLOT(SetEditCurrentArgument()));
94   connect(myGeomGUI->getApp()->selectionMgr(),
95                                 SIGNAL(currentSelectionChanged()),
96           this,                 SLOT(SelectionIntoArgument()));
97   connect(myGeomGUI,            SIGNAL(SignalDeactivateActiveDialog()),
98           this,                 SLOT(DeactivateActiveDialog()));
99   connect(myGeomGUI,            SIGNAL(SignalCloseAllDialogs()),
100           this,                 SLOT(ClickOnCancel()));
101   connect(buttonOk(),           SIGNAL(clicked()), this, SLOT(ClickOnOk()));
102   connect(buttonApply(),        SIGNAL(clicked()), this, SLOT(ClickOnApply()));
103
104   myEditCurrentArgument = myGroup->LineEdit1;
105   myGroup->LineEdit1->setReadOnly(true);
106   SelectionIntoArgument();
107 }
108
109 //=================================================================================
110 // function : SelectionIntoArgument
111 // purpose  : Called when selection is changed
112 //=================================================================================
113 void EntityGUI_SurfFromFaceDlg::SelectionIntoArgument()
114 {
115   erasePreview();
116   myEditCurrentArgument->setText("");
117   myFace.nullify();
118
119   GEOM::GeomObjPtr aSelectedObject = getSelected(TopAbs_FACE);
120
121   if (aSelectedObject) {
122     myEditCurrentArgument->setText(GEOMBase::GetName(aSelectedObject.get()));
123     myFace = aSelectedObject;
124   }
125
126   processPreview();
127 }
128
129 //=================================================================================
130 // function : SetEditCurrentArgument()
131 // purpose  :
132 //=================================================================================
133 void EntityGUI_SurfFromFaceDlg::SetEditCurrentArgument()
134 {
135   QPushButton* send = (QPushButton*)sender();
136
137   if (send == myGroup->PushButton1) {
138     myEditCurrentArgument->setFocus();
139     SelectionIntoArgument();
140   }
141 }
142
143 //=================================================================================
144 // function : ActivateThisDialog
145 // purpose  :
146 //=================================================================================
147 void EntityGUI_SurfFromFaceDlg::ActivateThisDialog()
148 {
149   GEOMBase_Skeleton::ActivateThisDialog();
150   connect(myGeomGUI->getApp()->selectionMgr(),
151                        SIGNAL(currentSelectionChanged()),
152           this,        SLOT(SelectionIntoArgument()));
153   SelectionIntoArgument();
154 }
155
156 //=================================================================================
157 // function : enterEvent()
158 // purpose  :
159 //=================================================================================
160 void EntityGUI_SurfFromFaceDlg::enterEvent (QEvent*)
161 {
162   if (!mainFrame()->GroupConstructors->isEnabled())
163     ActivateThisDialog();
164 }
165
166 //=================================================================================
167 // function : createOperation
168 // purpose  :
169 //=================================================================================
170 GEOM::GEOM_IOperations_ptr EntityGUI_SurfFromFaceDlg::createOperation()
171 {
172   return myGeomGUI->GetGeomGen()->GetIShapesOperations();
173 }
174
175 //=================================================================================
176 // function : isValid
177 // purpose  :
178 //=================================================================================
179 bool EntityGUI_SurfFromFaceDlg::isValid (QString& /*msg*/)
180 {
181   return myFace;
182 }
183
184 //=================================================================================
185 // function : execute
186 // purpose  :
187 //=================================================================================
188 bool EntityGUI_SurfFromFaceDlg::execute (ObjectList& objects)
189 {
190   GEOM::GEOM_IShapesOperations_var anOper =
191     GEOM::GEOM_IShapesOperations::_narrow(getOperation());
192   GEOM::GEOM_Object_var anObj = anOper->MakeSurfaceFromFace(myFace.get());
193
194   if (!anObj->_is_nil()) {
195     objects.push_back(anObj._retn());
196   }
197
198   return true;
199 }
200
201 //=================================================================================
202 // function : ClickOnOk()
203 // purpose  :
204 //=================================================================================
205 void EntityGUI_SurfFromFaceDlg::ClickOnOk()
206 {
207   setIsApplyAndClose(true);
208
209   if (ClickOnApply())
210     ClickOnCancel();
211 }
212
213 //=================================================================================
214 // function : ClickOnApply()
215 // purpose  :
216 //=================================================================================
217 bool EntityGUI_SurfFromFaceDlg::ClickOnApply()
218 {
219   if (!onAccept())
220     return false;
221
222   initName();
223
224   return true;
225 }
226
227 //=================================================================================
228 // function : getSourceObjects
229 // purpose  : virtual method to get source objects
230 //=================================================================================
231 QList<GEOM::GeomObjPtr> EntityGUI_SurfFromFaceDlg::getSourceObjects()
232 {
233   QList<GEOM::GeomObjPtr> res;
234   res << myFace;
235   return res;
236 }