1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : TransformationGUI_ProjectionDlg.cxx
24 // Author : Lucien PIGNOLONI, Open CASCADE S.A.S.
26 #include "TransformationGUI.h"
27 #include "TransformationGUI_ProjectionDlg.h"
30 #include <GeometryGUI.h>
32 #include <GEOMImpl_Types.hxx>
34 #include <SUIT_Session.h>
35 #include <SUIT_ResourceMgr.h>
36 #include <SalomeApp_Application.h>
37 #include <LightApp_SelectionMgr.h>
39 #include <TColStd_MapOfInteger.hxx>
43 enum EOperationType { PROJ_ON_FACE = 0, PROJ_ON_WIRE, PROJ_ON_EDGE };
46 //=================================================================================
47 // class : TransformationGUI_ProjectionDlg()
48 // purpose : Constructs a TransformationGUI_ProjectionDlg which is a child of 'parent', with the
49 // name 'name' and widget flags set to 'f'.
50 // The dialog will by default be modeless, unless you set 'modal' to
51 // TRUE to construct a modal dialog.
52 //=================================================================================
53 TransformationGUI_ProjectionDlg::TransformationGUI_ProjectionDlg (GeometryGUI* theGeometryGUI,
54 QWidget* parent, bool modal, Qt::WindowFlags fl)
55 : GEOMBase_Skeleton(theGeometryGUI, parent, modal, fl)
57 QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT")));
58 QPixmap image2 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PROJECTION_ON_FACE")));
59 QPixmap image3 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PROJECTION_ON_WIRE")));
60 QPixmap image4 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_PROJECTION_ON_EDGE")));
62 setWindowTitle(tr("GEOM_PROJECTION_TITLE"));
64 mainFrame()->RadioButton1->setIcon(image2);
65 mainFrame()->RadioButton2->setIcon(image3);
66 mainFrame()->RadioButton3->setIcon(image4);
68 myGroup = new DlgRef_2Sel (centralWidget());
70 myGroup->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
71 myGroup->PushButton1->setIcon(image1);
72 myGroup->PushButton2->setIcon(image1);
73 myGroup->LineEdit1->setReadOnly(true);
74 myGroup->LineEdit2->setReadOnly(true);
76 QVBoxLayout* layout = new QVBoxLayout(centralWidget());
77 layout->setMargin(0); layout->setSpacing(6);
78 layout->addWidget(myGroup);
80 setHelpFileName("projection_operation_page.html");
86 //=================================================================================
87 // function : ~TransformationGUI_ProjectionDlg()
88 // purpose : Destroys the object and frees any allocated resources
89 //=================================================================================
90 TransformationGUI_ProjectionDlg::~TransformationGUI_ProjectionDlg()
94 //=================================================================================
97 //=================================================================================
98 void TransformationGUI_ProjectionDlg::Init()
100 mainFrame()->GroupBoxPublish->show();
103 myEditCurrentArgument = myGroup->LineEdit1;
105 myGroup->LineEdit1->setText("");
106 myGroup->LineEdit2->setText("");
110 showOnlyPreviewControl();
112 // signals and slots connections
113 connect(this, SIGNAL( constructorsClicked( int )),
114 this, SLOT ( ConstructorsClicked( int )));
115 connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk()));
116 connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply()));
118 connect(myGroup->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
119 connect(myGroup->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
121 connect(((SalomeApp_Application*)(SUIT_Session::session()->activeApplication()))->selectionMgr(),
122 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
124 initName( windowTitle() );
126 setTabOrder(mainFrame()->GroupConstructors, mainFrame()->GroupBoxName);
127 setTabOrder(mainFrame()->GroupBoxName, mainFrame()->GroupMedium);
128 setTabOrder(mainFrame()->GroupMedium, mainFrame()->GroupButtons);
130 //mainFrame()->RadioButton1->setFocus();
131 ConstructorsClicked( 0 );
136 //=================================================================================
137 // function : ClickOnOk()
139 //=================================================================================
140 void TransformationGUI_ProjectionDlg::ClickOnOk()
142 setIsApplyAndClose(true);
147 //=================================================================================
148 // function : ClickOnApply()
150 //=================================================================================
151 bool TransformationGUI_ProjectionDlg::ClickOnApply()
157 ConstructorsClicked( getConstructorId() );
162 //=================================================================================
163 // function : SelectionIntoArgument()
164 // purpose : Called when selection is changed or on dialog initialization or activation
165 //=================================================================================
166 void TransformationGUI_ProjectionDlg::SelectionIntoArgument()
168 myEditCurrentArgument->setText("");
170 GEOM::GeomObjPtr aSelectedObject;
171 if ( myEditCurrentArgument == myGroup->LineEdit1 ) // what to project
172 switch( getConstructorId() ) {
173 case PROJ_ON_FACE: aSelectedObject = getSelected(TopAbs_SHAPE); break;
175 case PROJ_ON_EDGE: aSelectedObject = getSelected(TopAbs_VERTEX); break;
179 switch( getConstructorId() ) { // where to project
180 case PROJ_ON_FACE: aSelectedObject = getSelected(TopAbs_FACE); break;
181 case PROJ_ON_WIRE: aSelectedObject = getSelected(TopAbs_WIRE); break;
182 case PROJ_ON_EDGE: aSelectedObject = getSelected(TopAbs_EDGE); break;
187 if (aSelectedObject && GEOMBase::GetShape(aSelectedObject.get(), aShape) && !aShape.IsNull())
189 QString aName = GEOMBase::GetName(aSelectedObject.get());
190 myEditCurrentArgument->setText(aName);
193 disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0);
194 myGeomGUI->getApp()->selectionMgr()->clearSelected();
195 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
196 this, SLOT(SelectionIntoArgument()));
198 if (myEditCurrentArgument == myGroup->LineEdit1) {
199 myObject1 = aSelectedObject;
201 myGroup->PushButton2->click();
203 else if (myEditCurrentArgument == myGroup->LineEdit2) {
204 myObject2 = aSelectedObject;
206 myGroup->PushButton1->click();
210 if (myEditCurrentArgument == myGroup->LineEdit1) myObject1.nullify();
211 else if (myEditCurrentArgument == myGroup->LineEdit2) myObject2.nullify();
216 //=================================================================================
217 // function : SetEditCurrentArgument()
219 //=================================================================================
220 void TransformationGUI_ProjectionDlg::SetEditCurrentArgument()
222 QPushButton* send = (QPushButton*)sender();
224 globalSelection(); // close local contexts, if any
226 if (send == myGroup->PushButton1) // what to project
228 myEditCurrentArgument = myGroup->LineEdit1;
230 myGroup->PushButton2->setDown(false);
231 myGroup->LineEdit2->setEnabled(false);
233 switch ( getConstructorId() ) {
235 TColStd_MapOfInteger aMap;
236 aMap.Add( GEOM_POINT );
237 aMap.Add( GEOM_EDGE );
238 aMap.Add( GEOM_WIRE );
239 globalSelection( aMap );
240 std::list<int> needTypes;
241 needTypes.push_back( TopAbs_VERTEX ), needTypes.push_back( TopAbs_EDGE ), needTypes.push_back( TopAbs_WIRE );
242 localSelection(GEOM::GEOM_Object::_nil(), needTypes );
247 localSelection(GEOM::GEOM_Object::_nil(), TopAbs_VERTEX);
253 else if (send == myGroup->PushButton2) // where to project
255 myEditCurrentArgument = myGroup->LineEdit2;
257 myGroup->PushButton1->setDown(false);
258 myGroup->LineEdit1->setEnabled(false);
260 switch ( getConstructorId() ) {
261 case PROJ_ON_FACE: localSelection(GEOM::GEOM_Object::_nil(), TopAbs_FACE); break;
262 case PROJ_ON_WIRE: localSelection(GEOM::GEOM_Object::_nil(), TopAbs_WIRE); break;
263 case PROJ_ON_EDGE: localSelection(GEOM::GEOM_Object::_nil(), TopAbs_EDGE); break;
269 myEditCurrentArgument->setEnabled(true);
270 myEditCurrentArgument->setFocus();
271 // after setFocus(), because it will be setDown(false) when loses focus
274 SelectionIntoArgument();
277 //=================================================================================
278 // function : ActivateThisDialog()
280 //=================================================================================
281 void TransformationGUI_ProjectionDlg::ActivateThisDialog()
283 GEOMBase_Skeleton::ActivateThisDialog();
285 connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()),
286 this, SLOT(SelectionIntoArgument()));
290 //=================================================================================
291 // function : enterEvent()
292 // purpose : when mouse enter onto the QWidget
293 //=================================================================================
294 void TransformationGUI_ProjectionDlg::enterEvent (QEvent*)
296 if (!mainFrame()->GroupConstructors->isEnabled())
297 ActivateThisDialog();
300 //=================================================================================
301 // function : createOperation
303 //=================================================================================
304 GEOM::GEOM_IOperations_ptr TransformationGUI_ProjectionDlg::createOperation()
306 return getGeomEngine()->GetITransformOperations(getStudyId());
309 //=================================================================================
310 // function : isValid
312 //=================================================================================
313 bool TransformationGUI_ProjectionDlg::isValid (QString&)
315 return myObject1 && myObject2;
318 //=================================================================================
319 // function : execute
321 //=================================================================================
322 bool TransformationGUI_ProjectionDlg::execute (ObjectList& objects)
324 GEOM::GEOM_Object_var anObj;
326 GEOM::GEOM_ITransformOperations_var anOper = GEOM::GEOM_ITransformOperations::_narrow(getOperation());
327 anObj = anOper->ProjectShapeCopy( myObject1.get(), myObject2.get() );
328 if (!anObj->_is_nil())
329 objects.push_back(anObj._retn());
334 //=================================================================================
335 // function : ConstructorsClicked()
336 // purpose : Radio button management
337 //=================================================================================
338 void TransformationGUI_ProjectionDlg::ConstructorsClicked( int constructorId )
342 myGroup->LineEdit1->setText( "" );
343 myGroup->LineEdit2->setText( "" );
345 switch ( constructorId ) {
347 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION_ON_FACE"));
348 myGroup->TextLabel1->setText(tr("GEOM_PROJ_ON_FACE_SOURCE"));
349 myGroup->TextLabel2->setText(tr("GEOM_PROJ_ON_FACE_TARGET"));
352 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION_ON_EDGE"));
353 myGroup->TextLabel1->setText(tr("GEOM_PROJ_ON_EDGE_SOURCE"));
354 myGroup->TextLabel2->setText(tr("GEOM_PROJ_ON_EDGE_TARGET"));
357 mainFrame()->GroupConstructors->setTitle(tr("GEOM_PROJECTION_ON_WIRE"));
358 myGroup->TextLabel1->setText(tr("GEOM_PROJ_ON_WIRE_SOURCE"));
359 myGroup->TextLabel2->setText(tr("GEOM_PROJ_ON_WIRE_TARGET"));
363 myGroup->PushButton1->click();
366 //=================================================================================
367 // function : addSubshapeToStudy
368 // purpose : virtual method to add new SubObjects if local selection
369 //=================================================================================
370 void TransformationGUI_ProjectionDlg::addSubshapesToStudy()
372 GEOMBase::PublishSubObject( myObject1.get() );
373 GEOMBase::PublishSubObject( myObject2.get() );