1 // GEOM GEOMGUI : GUI for Geometry component
3 // Copyright (C) 2003 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.
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
24 // File : TransformationGUI_ScaleDlg.cxx
25 // Author : Lucien PIGNOLONI
29 #include "TransformationGUI_ScaleDlg.h"
31 #include "SUIT_Desktop.h"
32 #include "SUIT_Session.h"
33 #include "SalomeApp_Application.h"
34 #include "LightApp_SelectionMgr.h"
36 #include <TopoDS_Shape.hxx>
39 #include <TColStd_IndexedMapOfInteger.hxx>
40 #include <TopTools_IndexedMapOfShape.hxx>
43 #include <qcheckbox.h>
45 #include "GEOMImpl_Types.hxx"
47 #include "utilities.h"
51 //=================================================================================
52 // class : TransformationGUI_ScaleDlg()
53 // purpose : Constructs a TransformationGUI_ScaleDlg which is a child of 'parent', with the
54 // name 'name' and widget flags set to 'f'.
55 // The dialog will by default be modeless, unless you set 'modal' to
56 // TRUE to construct a modal dialog.
57 //=================================================================================
58 TransformationGUI_ScaleDlg::TransformationGUI_ScaleDlg(GeometryGUI* theGeometryGUI, QWidget* parent,
59 const char* name, bool modal, WFlags fl)
60 :GEOMBase_Skeleton(theGeometryGUI, parent, name, modal, WStyle_Customize |
61 WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
63 QPixmap image0(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_DLG_SCALE")));
64 QPixmap image1(SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM",tr("ICON_SELECT")));
66 setCaption(tr("GEOM_SCALE_TITLE"));
68 /***************************************************************/
69 GroupConstructors->setTitle(tr("GEOM_SCALE"));
70 RadioButton1->setPixmap(image0);
71 RadioButton2->close(TRUE);
72 RadioButton3->close(TRUE);
74 GroupPoints = new DlgRef_2Sel1Spin2Check(this, "GroupPoints");
75 GroupPoints->CheckButton2->hide();
76 GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS"));
77 GroupPoints->TextLabel1->setText(tr("GEOM_OBJECTS"));
78 GroupPoints->TextLabel2->setText(tr("GEOM_CENTRAL_POINT"));
79 GroupPoints->TextLabel3->setText(tr("GEOM_SCALE_FACTOR"));
80 GroupPoints->LineEdit1->setReadOnly( true );
81 GroupPoints->LineEdit2->setReadOnly( true );
82 GroupPoints->PushButton1->setPixmap(image1);
83 GroupPoints->PushButton2->setPixmap(image1);
84 GroupPoints->CheckButton1->setText(tr("GEOM_CREATE_COPY"));
86 // san -- modification of an exisitng object by offset is not allowed
87 GroupPoints->CheckButton1->hide();
89 Layout1->addWidget(GroupPoints, 2, 0);
90 /***************************************************************/
92 double SpecificStep = 0.5;
93 /* min, max, step and decimals for spin boxes & initial values */
94 GroupPoints->SpinBox_DX->RangeStepAndValidator(COORD_MIN, COORD_MAX, SpecificStep, DBL_DIGITS_DISPLAY);
95 GroupPoints->SpinBox_DX->SetValue(aFactor);
97 // Activate Create a Copy mode
98 GroupPoints->CheckButton1->setChecked(true);
99 CreateCopyModeChanged(true);
101 GroupBoxPublish->show();
103 /* signals and slots connections */
104 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
105 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
107 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
108 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
110 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
111 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
113 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox()));
114 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
115 connect(GroupPoints->CheckButton1, SIGNAL(toggled(bool)), this, SLOT(CreateCopyModeChanged(bool)));
117 connect(myGeomGUI->getApp()->selectionMgr(),
118 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument())) ;
120 setHelpFileName("scale_operation_page.html");
126 //=================================================================================
127 // function : ~TransformationGUI_ScaleDlg()
128 // purpose : Destroys the object and frees any allocated resources
129 //=================================================================================
130 TransformationGUI_ScaleDlg::~TransformationGUI_ScaleDlg()
132 /* no need to delete child widgets, Qt does it all for us */
136 //=================================================================================
139 //=================================================================================
140 void TransformationGUI_ScaleDlg::Init()
142 myEditCurrentArgument = GroupPoints->LineEdit1;
143 GroupPoints->LineEdit2->clear();
145 myPoint = GEOM::GEOM_Object::_nil();
147 initName( tr( "GEOM_SCALE" ) );
151 //=================================================================================
152 // function : ClickOnOk()
154 //=================================================================================
155 void TransformationGUI_ScaleDlg::ClickOnOk()
157 if ( ClickOnApply() )
162 //=================================================================================
163 // function : ClickOnApply()
165 //=================================================================================
166 bool TransformationGUI_ScaleDlg::ClickOnApply()
168 if ( !onAccept(GroupPoints->CheckButton1->isChecked()) )
176 //=================================================================================
177 // function : SelectionIntoArgument()
178 // purpose : Called when selection as changed or other case
179 //=================================================================================
180 void TransformationGUI_ScaleDlg::SelectionIntoArgument()
182 myEditCurrentArgument->setText("");
185 if(myEditCurrentArgument == GroupPoints->LineEdit1)
187 int aNbSel = GEOMBase::GetNameOfSelectedIObjects(selectedIO(), aName);
193 GEOMBase::ConvertListOfIOInListOfGO(selectedIO(), myObjects);
194 if (!myObjects.length())
197 else if(myEditCurrentArgument == GroupPoints->LineEdit2)
199 if(IObjectCount() != 1)
201 myPoint = GEOM::GEOM_Object::_nil();
204 Standard_Boolean testResult = Standard_False;
205 GEOM::GEOM_Object_var aSelectedObject = GEOMBase::ConvertIOinGEOMObject(firstIObject(), testResult );
206 aName = GEOMBase::GetName( aSelectedObject );
209 if ( GEOMBase::GetShape( aSelectedObject, aShape, TopAbs_SHAPE ) && !aShape.IsNull() )
211 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
212 TColStd_IndexedMapOfInteger aMap;
213 aSelMgr->GetIndexes( firstIObject(), aMap );
214 if ( aMap.Extent() == 1 )
216 int anIndex = aMap( 1 );
217 aName += QString(":vertex_%1").arg(anIndex);
219 //Find SubShape Object in Father
220 GEOM::GEOM_Object_var aFindedObject = findObjectInFather(aSelectedObject, aName);
222 if ( aFindedObject == GEOM::GEOM_Object::_nil() ) { // Object not found in study
223 GEOM::GEOM_IShapesOperations_var aShapesOp =
224 getGeomEngine()->GetIShapesOperations( getStudyId() );
225 aSelectedObject = aShapesOp->GetSubShape(aSelectedObject, anIndex);
226 aSelMgr->clearSelected();
229 aSelectedObject = aFindedObject; // get Object from study
232 if (aShape.ShapeType() != TopAbs_VERTEX) {
233 aSelectedObject = GEOM::GEOM_Object::_nil();
239 myPoint = aSelectedObject;
241 if(!testResult || CORBA::is_nil( myPoint ))
245 myEditCurrentArgument->setText( aName );
251 //=================================================================================
252 // function : LineEditReturnPressed()
254 //=================================================================================
255 void TransformationGUI_ScaleDlg::LineEditReturnPressed()
257 QLineEdit* send = (QLineEdit*)sender();
258 if(send == GroupPoints->LineEdit1 ||
259 send == GroupPoints->LineEdit2)
261 myEditCurrentArgument = send;
262 GEOMBase_Skeleton::LineEditReturnPressed();
267 //=================================================================================
268 // function : SetEditCurrentArgument()
270 //=================================================================================
271 void TransformationGUI_ScaleDlg::SetEditCurrentArgument()
273 QPushButton* send = (QPushButton*)sender();
276 if(send == GroupPoints->PushButton1) {
277 myEditCurrentArgument = GroupPoints->LineEdit1;
279 else if(send == GroupPoints->PushButton2) {
280 myEditCurrentArgument = GroupPoints->LineEdit2;
281 localSelection( GEOM::GEOM_Object::_nil(), TopAbs_VERTEX );
284 myEditCurrentArgument->setFocus();
285 SelectionIntoArgument();
289 //=================================================================================
290 // function : ActivateThisDialog()
292 //=================================================================================
293 void TransformationGUI_ScaleDlg::ActivateThisDialog()
295 GEOMBase_Skeleton::ActivateThisDialog();
296 connect(myGeomGUI->getApp()->selectionMgr(),
297 SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
299 GroupPoints->LineEdit1->setFocus();
300 myEditCurrentArgument = GroupPoints->LineEdit1;
304 //=================================================================================
305 // function : enterEvent()
307 //=================================================================================
308 void TransformationGUI_ScaleDlg::enterEvent(QEvent* e)
310 if( !GroupConstructors->isEnabled() )
311 ActivateThisDialog();
315 //=================================================================================
316 // function : ValueChangedInSpinBox()
318 //=================================================================================
319 void TransformationGUI_ScaleDlg::ValueChangedInSpinBox()
325 //=================================================================================
326 // function : createOperation
328 //=================================================================================
329 GEOM::GEOM_IOperations_ptr TransformationGUI_ScaleDlg::createOperation()
331 return myGeomGUI->GetGeomGen()->GetITransformOperations( getStudyId() );
334 //=================================================================================
335 // function : isValid
337 //=================================================================================
338 bool TransformationGUI_ScaleDlg::isValid( QString& msg )
340 return !(myObjects.length() == 0 || myPoint->_is_nil() || fabs(GetFactor()) <= 0.00001);
344 //=================================================================================
345 // function : execute
347 //=================================================================================
348 bool TransformationGUI_ScaleDlg::execute( ObjectList& objects )
352 GEOM::GEOM_Object_var anObj;
354 if (GroupPoints->CheckButton1->isChecked() || IsPreview())
355 for (int i = 0; i < myObjects.length(); i++)
357 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
358 ScaleShapeCopy( myObjects[i], myPoint, GetFactor() );
359 if ( !anObj->_is_nil() )
360 objects.push_back( anObj._retn() );
363 for (int i = 0; i < myObjects.length(); i++)
365 anObj = GEOM::GEOM_ITransformOperations::_narrow( getOperation() )->
366 ScaleShape( myObjects[i], myPoint, GetFactor() );
367 if ( !anObj->_is_nil() )
368 objects.push_back( anObj._retn() );
375 //=================================================================================
376 // function : restoreSubShapes
378 //=================================================================================
379 void TransformationGUI_ScaleDlg::restoreSubShapes (SALOMEDS::Study_ptr theStudy,
380 SALOMEDS::SObject_ptr theSObject)
382 if (CheckBoxRestoreSS->isChecked()) {
383 // empty list of arguments means that all arguments should be restored
384 getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(), /*isTrsf=*/true);
388 //=================================================================================
389 // function : GetFactor()
391 //=================================================================================
392 double TransformationGUI_ScaleDlg::GetFactor() const
394 return GroupPoints->SpinBox_DX->GetValue();
398 //=================================================================================
399 // function : CreateCopyModeChanged()
401 //=================================================================================
402 void TransformationGUI_ScaleDlg::CreateCopyModeChanged(bool isCreateCopy)
404 this->GroupBoxName->setEnabled(isCreateCopy);
407 //=================================================================================
408 // function : addSubshapeToStudy
409 // purpose : virtual method to add new SubObjects if local selection
410 //=================================================================================
411 void TransformationGUI_ScaleDlg::addSubshapesToStudy()
413 bool toCreateCopy = IsPreview() || GroupPoints->CheckButton1->isChecked();
415 QMap<QString, GEOM::GEOM_Object_var> objMap;
417 objMap[GroupPoints->LineEdit2->text()] = myPoint;
419 addSubshapesToFather( objMap );