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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : TransformationGUI_MultiTranslationDlg.cxx
25 // Author : Damien COQUERET
30 #include "TransformationGUI_MultiTranslationDlg.h"
33 #include <BRepBuilderAPI_MakeVertex.hxx>
34 #include <BRepBuilderAPI_Transform.hxx>
35 #include <BRepAdaptor_Curve.hxx>
36 #include <BRep_Builder.hxx>
37 #include <BRepGProp.hxx>
38 #include <GProp_GProps.hxx>
39 #include <TopoDS_Compound.hxx>
40 #include "QAD_Config.h"
42 //=================================================================================
43 // class : TransformationGUI_MultiTranslationDlg()
44 // purpose : Constructs a TransformationGUI_MultiTranslationDlg 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 TransformationGUI_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
50 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
52 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_MULTITRANSLATION_SIMPLE")));
53 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
54 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
56 setCaption(tr("GEOM_MULTITRANSLATION_TITLE"));
58 /***************************************************************/
59 GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
60 RadioButton1->setPixmap(image0);
61 RadioButton2->setPixmap(image1);
62 RadioButton3->close(TRUE);
64 GroupPoints = new DlgRef_2Sel2Spin1Check(this, "GroupPoints");
65 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
66 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
67 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
68 GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
69 GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
70 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
71 GroupPoints->PushButton1->setPixmap(image2);
72 GroupPoints->PushButton2->setPixmap(image2);
74 GroupDimensions = new DlgRef_3Sel4Spin2Check(this, "GroupDimensions");
75 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
76 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
77 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
78 GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
79 GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
80 GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
81 GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
82 GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
83 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
84 GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
85 GroupDimensions->PushButton1->setPixmap(image2);
86 GroupDimensions->PushButton2->setPixmap(image2);
87 GroupDimensions->PushButton3->setPixmap(image2);
89 Layout1->addWidget(GroupPoints, 1, 0);
90 Layout1->addWidget(GroupDimensions, 1, 0);
91 /***************************************************************/
94 myTransformationGUI = theTransformationGUI;
99 //=================================================================================
100 // function : ~TransformationGUI_MultiTranslationDlg()
101 // purpose : Destroys the object and frees any allocated resources
102 //=================================================================================
103 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
105 // no need to delete child widgets, Qt does it all for us
109 //=================================================================================
112 //=================================================================================
113 void TransformationGUI_MultiTranslationDlg::Init()
117 myEditCurrentArgument = GroupPoints->LineEdit1;
123 myOkBase = myOkDir1 = myOkDir2 = false;
125 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
127 /* Get setting of step value from file configuration */
128 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
129 step = St.toDouble();
131 double SpecificStep = 1;
132 /* min, max, step and decimals for spin boxes & initial values */
133 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
134 GroupPoints->SpinBox_DY->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
135 GroupPoints->SpinBox_DX->SetValue(myStep1);
136 GroupPoints->SpinBox_DY->SetValue(myNbTimes1);
138 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, step, 3);
139 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
140 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
141 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
142 GroupDimensions->SpinBox_DX1->SetValue(myStep1);
143 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
144 GroupDimensions->SpinBox_DX2->SetValue(myStep2);
145 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
147 /* signals and slots connections */
148 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
149 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
150 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
152 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
153 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
155 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
161 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
164 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
165 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
167 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
169 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
171 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
172 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
173 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
174 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
175 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
176 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
178 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle1(int)));
179 connect(GroupDimensions->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle1(int)));
180 connect(GroupDimensions->CheckButton2, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle2(int)));
182 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
184 /* displays Dialog */
185 GroupDimensions->hide();
193 //=================================================================================
194 // function : ConstructorsClicked()
195 // purpose : Radio button management
196 //=================================================================================
197 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked(int constructorId)
199 myConstructorId = constructorId;
200 mySelection->ClearFilters();
201 myGeomBase->EraseSimulationShape();
202 mySimulationTopoDs.Nullify();
203 disconnect(mySelection, 0, this, 0);
208 myOkBase = myOkDir1 = myOkDir2 = false;
210 switch (constructorId)
212 case 0: /* Translate simple */
214 GroupDimensions->hide();
218 myEditCurrentArgument = GroupPoints->LineEdit1;
219 GroupPoints->LineEdit1->setText("");
220 GroupPoints->LineEdit2->setText("");
222 GroupPoints->SpinBox_DX->SetValue(myStep1);
223 GroupPoints->SpinBox_DY->SetValue(myNbTimes1);
225 /* filter for next selection */
226 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
229 case 1: /* Translate double */
233 GroupDimensions->show();
235 myEditCurrentArgument = GroupDimensions->LineEdit1;
236 GroupDimensions->LineEdit1->setText("");
237 GroupDimensions->LineEdit2->setText("");
238 GroupDimensions->LineEdit3->setText("");
240 GroupDimensions->SpinBox_DX1->SetValue(myStep1);
241 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
242 GroupDimensions->SpinBox_DX2->SetValue(myStep2);
243 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
245 /* filter for next selection */
246 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
254 //=================================================================================
255 // function : ClickOnOk()
257 //=================================================================================
258 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
260 this->ClickOnApply();
266 //=================================================================================
267 // function : ClickOnApply()
269 //=================================================================================
270 void TransformationGUI_MultiTranslationDlg::ClickOnApply()
272 buttonApply->setFocus();
273 QAD_Application::getDesktop()->putInfo(tr(""));
274 if (mySimulationTopoDs.IsNull())
276 myGeomBase->EraseSimulationShape();
277 mySimulationTopoDs.Nullify();
279 if(myConstructorId == 0) {
280 if(myOkBase && myOkDir1)
281 myTransformationGUI->MakeMultiTranslation1DAndDisplay(myGeomShape, myDir1, myStep1, myNbTimes1);
283 else if(myConstructorId == 1) {
284 if(myOkBase && myOkDir1 && myOkDir2)
285 myTransformationGUI->MakeMultiTranslation2DAndDisplay(myGeomShape, myDir1, myStep1, myNbTimes1, myDir2, myStep2, myNbTimes2);
291 //=================================================================================
292 // function : SelectionIntoArgument()
293 // purpose : Called when selection as changed or other case
294 //=================================================================================
295 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
297 myGeomBase->EraseSimulationShape();
298 mySimulationTopoDs.Nullify();
299 myEditCurrentArgument->setText("");
300 QString aString = ""; /* name of selection */
302 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
304 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
306 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
308 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
315 Standard_Boolean testResult;
316 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
317 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
320 switch(myConstructorId)
324 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
325 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
328 myEditCurrentArgument->setText(aString);
332 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
333 BRepAdaptor_Curve curv(TopoDS::Edge(S));
334 myDir1 = curv.Line().Direction();
335 myEditCurrentArgument->setText(aString);
339 if(myOkBase && myOkDir1)
340 this->MakeMultiTranslationSimulationAndDisplay();
345 if(myEditCurrentArgument == GroupDimensions->LineEdit1) {
346 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
349 myEditCurrentArgument->setText(aString);
353 else if(myEditCurrentArgument == GroupDimensions->LineEdit2) {
354 BRepAdaptor_Curve curv(TopoDS::Edge(S));
355 myDir1 = curv.Line().Direction();
356 myEditCurrentArgument->setText(aString);
359 else if(myEditCurrentArgument == GroupDimensions->LineEdit3) {
360 BRepAdaptor_Curve curv(TopoDS::Edge(S));
361 myDir2 = curv.Line().Direction();
362 myEditCurrentArgument->setText(aString);
366 if(myOkBase && myOkDir1 && myOkDir2)
367 this->MakeMultiTranslationSimulationAndDisplay();
375 //=================================================================================
376 // function : SetEditCurrentArgument()
378 //=================================================================================
379 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
381 QPushButton* send = (QPushButton*)sender();
382 mySelection->ClearFilters();
384 if(send == GroupPoints->PushButton1) {
385 GroupPoints->LineEdit1->setFocus();
386 myEditCurrentArgument = GroupPoints->LineEdit1;
388 else if(send == GroupPoints->PushButton2) {
389 GroupPoints->LineEdit2->setFocus();
390 myEditCurrentArgument = GroupPoints->LineEdit2;
391 mySelection->AddFilter(myEdgeFilter);
393 else if(send == GroupDimensions->PushButton1) {
394 GroupDimensions->LineEdit1->setFocus();
395 myEditCurrentArgument = GroupDimensions->LineEdit1;
397 else if(send == GroupDimensions->PushButton2) {
398 GroupDimensions->LineEdit2->setFocus();
399 myEditCurrentArgument = GroupDimensions->LineEdit2;
400 mySelection->AddFilter(myEdgeFilter);
402 else if(send == GroupDimensions->PushButton3) {
403 GroupDimensions->LineEdit3->setFocus();
404 myEditCurrentArgument = GroupDimensions->LineEdit3;
405 mySelection->AddFilter(myEdgeFilter);
407 this->SelectionIntoArgument();
413 //=================================================================================
414 // function : LineEditReturnPressed()
416 //=================================================================================
417 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
419 QLineEdit* send = (QLineEdit*)sender();
420 if(send == GroupPoints->LineEdit1)
421 myEditCurrentArgument = GroupPoints->LineEdit1;
422 else if (send == GroupPoints->LineEdit2)
423 myEditCurrentArgument = GroupPoints->LineEdit2;
424 else if (send == GroupDimensions->LineEdit1)
425 myEditCurrentArgument = GroupDimensions->LineEdit1;
426 else if (send == GroupDimensions->LineEdit2)
427 myEditCurrentArgument = GroupDimensions->LineEdit2;
428 else if (send == GroupDimensions->LineEdit3)
429 myEditCurrentArgument = GroupDimensions->LineEdit3;
433 GEOMBase_Skeleton::LineEditReturnPressed();
438 //=================================================================================
439 // function : ActivateThisDialog()
441 //=================================================================================
442 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
444 GEOMBase_Skeleton::ActivateThisDialog();
445 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
447 if(myConstructorId == 0) {
448 GroupPoints->LineEdit1->setFocus();
449 myEditCurrentArgument = GroupPoints->LineEdit1;
451 else if(myConstructorId == 1) {
452 GroupDimensions->LineEdit1->setFocus();
453 myEditCurrentArgument = GroupDimensions->LineEdit1;
456 if(!mySimulationTopoDs.IsNull())
457 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
462 //=================================================================================
463 // function : enterEvent()
465 //=================================================================================
466 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
468 if (GroupConstructors->isEnabled())
470 this->ActivateThisDialog();
475 //=================================================================================
476 // function : ValueChangedInSpinBox()
478 //=================================================================================
479 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
481 myGeomBase->EraseSimulationShape();
482 mySimulationTopoDs.Nullify();
483 QObject* send = (QObject*)sender();
485 switch(myConstructorId)
489 if(send == GroupPoints->SpinBox_DX)
491 else if(send == GroupPoints->SpinBox_DY)
492 myNbTimes1 = (int)newValue;
493 if(myOkBase && myOkDir1)
494 this->MakeMultiTranslationSimulationAndDisplay();
499 if(send == GroupDimensions->SpinBox_DX1)
501 else if(send == GroupDimensions->SpinBox_DY1)
502 myNbTimes1 = (int)newValue;
503 else if(send == GroupDimensions->SpinBox_DX2)
505 else if(send == GroupDimensions->SpinBox_DY2)
506 myNbTimes2 = (int)newValue;
507 if(myOkBase && myOkDir1 && myOkDir2)
508 this->MakeMultiTranslationSimulationAndDisplay();
516 //=================================================================================
517 // function : ReverseAngle1()
518 // purpose : 'state' not used here
519 //=================================================================================
520 void TransformationGUI_MultiTranslationDlg::ReverseAngle1(int state)
523 if(myConstructorId == 0) {
524 GroupPoints->SpinBox_DX->SetValue(myStep1);
525 if(myOkBase && myOkDir1)
526 this->MakeMultiTranslationSimulationAndDisplay();
528 else if(myConstructorId == 1) {
529 GroupDimensions->SpinBox_DX1->SetValue(myStep1);
530 if(myOkBase && myOkDir1 && myOkDir2)
531 this->MakeMultiTranslationSimulationAndDisplay();
537 //=================================================================================
538 // function : ReverseAngle2()
539 // purpose : 'state' not used here
540 //=================================================================================
541 void TransformationGUI_MultiTranslationDlg::ReverseAngle2(int state)
544 GroupDimensions->SpinBox_DX2->SetValue(myStep2);
545 if(myOkBase && myOkDir1 && myOkDir2)
546 MakeMultiTranslationSimulationAndDisplay();
551 //=================================================================================
552 // function : MakeMultiTranslationSimulationAndDisplay()
554 //=================================================================================
555 void TransformationGUI_MultiTranslationDlg::MakeMultiTranslationSimulationAndDisplay()
557 myGeomBase->EraseSimulationShape();
558 mySimulationTopoDs.Nullify();
561 Standard_Real DX, DY, DZ;
562 gp_Trsf theTransformation;
564 TopoDS_Compound compound;
567 B.MakeCompound(compound);
570 BRepGProp::LinearProperties(myBase, System);
571 gp_Pnt myPoint = System.CentreOfMass();
572 TopoDS_Shape S = BRepBuilderAPI_MakeVertex(myPoint).Shape();
574 switch (myConstructorId)
581 for(i = 0; i < myNbTimes1; i++) {
582 DX = i * myStep1 * Vec.X();
583 DY = i * myStep1 * Vec.Y();
584 DZ = i * myStep1 * Vec.Z();
585 myVec.SetCoord(DX, DY, DZ);
587 theTransformation.SetTranslation(myVec);
588 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
589 B.Add(compound, myBRepTransformation.Shape());
591 mySimulationTopoDs = compound;
592 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
602 for(i = 0; i < myNbTimes1; i++) {
603 for(j = 0; j < myNbTimes2; j++) {
604 DX = i * myStep1 * Vec1.X() + j * myStep2 * Vec2.X();
605 DY = i * myStep1 * Vec1.Y() + j * myStep2 * Vec2.Y();
606 DZ = i * myStep1 * Vec1.Z() + j * myStep2 * Vec2.Z();
607 myVec.SetCoord(DX, DY, DZ);
609 theTransformation.SetTranslation(myVec);
610 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
611 B.Add(compound, myBRepTransformation.Shape());
614 mySimulationTopoDs = compound;
615 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
620 catch(Standard_Failure) {
621 MESSAGE("Exception catched in MakeMultitranslationSimulationAndDisplay");