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 QAD_Application::getDesktop()->putInfo(tr(""));
273 if (mySimulationTopoDs.IsNull())
275 myGeomBase->EraseSimulationShape();
276 mySimulationTopoDs.Nullify();
278 if(myConstructorId == 0) {
279 if(myOkBase && myOkDir1)
280 myTransformationGUI->MakeMultiTranslation1DAndDisplay(myGeomShape, myDir1, myStep1, myNbTimes1);
282 else if(myConstructorId == 1) {
283 if(myOkBase && myOkDir1 && myOkDir2)
284 myTransformationGUI->MakeMultiTranslation2DAndDisplay(myGeomShape, myDir1, myStep1, myNbTimes1, myDir2, myStep2, myNbTimes2);
290 //=================================================================================
291 // function : SelectionIntoArgument()
292 // purpose : Called when selection as changed or other case
293 //=================================================================================
294 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
296 myGeomBase->EraseSimulationShape();
297 mySimulationTopoDs.Nullify();
298 myEditCurrentArgument->setText("");
299 QString aString = ""; /* name of selection */
301 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
303 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
305 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
307 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
314 Standard_Boolean testResult;
315 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
316 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
319 switch(myConstructorId)
323 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
324 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
327 myEditCurrentArgument->setText(aString);
331 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
332 BRepAdaptor_Curve curv(TopoDS::Edge(S));
333 myDir1 = curv.Line().Direction();
334 myEditCurrentArgument->setText(aString);
338 if(myOkBase && myOkDir1)
339 this->MakeMultiTranslationSimulationAndDisplay();
344 if(myEditCurrentArgument == GroupDimensions->LineEdit1) {
345 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
348 myEditCurrentArgument->setText(aString);
352 else if(myEditCurrentArgument == GroupDimensions->LineEdit2) {
353 BRepAdaptor_Curve curv(TopoDS::Edge(S));
354 myDir1 = curv.Line().Direction();
355 myEditCurrentArgument->setText(aString);
358 else if(myEditCurrentArgument == GroupDimensions->LineEdit3) {
359 BRepAdaptor_Curve curv(TopoDS::Edge(S));
360 myDir2 = curv.Line().Direction();
361 myEditCurrentArgument->setText(aString);
365 if(myOkBase && myOkDir1 && myOkDir2)
366 this->MakeMultiTranslationSimulationAndDisplay();
374 //=================================================================================
375 // function : SetEditCurrentArgument()
377 //=================================================================================
378 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
380 QPushButton* send = (QPushButton*)sender();
381 mySelection->ClearFilters();
383 if(send == GroupPoints->PushButton1) {
384 GroupPoints->LineEdit1->setFocus();
385 myEditCurrentArgument = GroupPoints->LineEdit1;
387 else if(send == GroupPoints->PushButton2) {
388 GroupPoints->LineEdit2->setFocus();
389 myEditCurrentArgument = GroupPoints->LineEdit2;
390 mySelection->AddFilter(myEdgeFilter);
392 else if(send == GroupDimensions->PushButton1) {
393 GroupDimensions->LineEdit1->setFocus();
394 myEditCurrentArgument = GroupDimensions->LineEdit1;
396 else if(send == GroupDimensions->PushButton2) {
397 GroupDimensions->LineEdit2->setFocus();
398 myEditCurrentArgument = GroupDimensions->LineEdit2;
399 mySelection->AddFilter(myEdgeFilter);
401 else if(send == GroupDimensions->PushButton3) {
402 GroupDimensions->LineEdit3->setFocus();
403 myEditCurrentArgument = GroupDimensions->LineEdit3;
404 mySelection->AddFilter(myEdgeFilter);
406 this->SelectionIntoArgument();
412 //=================================================================================
413 // function : LineEditReturnPressed()
415 //=================================================================================
416 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
418 QLineEdit* send = (QLineEdit*)sender();
419 if(send == GroupPoints->LineEdit1)
420 myEditCurrentArgument = GroupPoints->LineEdit1;
421 else if (send == GroupPoints->LineEdit2)
422 myEditCurrentArgument = GroupPoints->LineEdit2;
423 else if (send == GroupDimensions->LineEdit1)
424 myEditCurrentArgument = GroupDimensions->LineEdit1;
425 else if (send == GroupDimensions->LineEdit2)
426 myEditCurrentArgument = GroupDimensions->LineEdit2;
427 else if (send == GroupDimensions->LineEdit3)
428 myEditCurrentArgument = GroupDimensions->LineEdit3;
432 GEOMBase_Skeleton::LineEditReturnPressed();
437 //=================================================================================
438 // function : ActivateThisDialog()
440 //=================================================================================
441 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
443 GEOMBase_Skeleton::ActivateThisDialog();
444 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
446 if(myConstructorId == 0) {
447 GroupPoints->LineEdit1->setFocus();
448 myEditCurrentArgument = GroupPoints->LineEdit1;
450 else if(myConstructorId == 1) {
451 GroupDimensions->LineEdit1->setFocus();
452 myEditCurrentArgument = GroupDimensions->LineEdit1;
455 if(!mySimulationTopoDs.IsNull())
456 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
461 //=================================================================================
462 // function : enterEvent()
464 //=================================================================================
465 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
467 if (GroupConstructors->isEnabled())
469 this->ActivateThisDialog();
474 //=================================================================================
475 // function : ValueChangedInSpinBox()
477 //=================================================================================
478 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
480 myGeomBase->EraseSimulationShape();
481 mySimulationTopoDs.Nullify();
482 QObject* send = (QObject*)sender();
484 switch(myConstructorId)
488 if(send == GroupPoints->SpinBox_DX)
490 else if(send == GroupPoints->SpinBox_DY)
491 myNbTimes1 = newValue;
492 if(myOkBase && myOkDir1)
493 this->MakeMultiTranslationSimulationAndDisplay();
498 if(send == GroupDimensions->SpinBox_DX1)
500 else if(send == GroupDimensions->SpinBox_DY1)
501 myNbTimes1 = newValue;
502 else if(send == GroupDimensions->SpinBox_DX2)
504 else if(send == GroupDimensions->SpinBox_DY2)
505 myNbTimes2 = newValue;
506 if(myOkBase && myOkDir1 && myOkDir2)
507 this->MakeMultiTranslationSimulationAndDisplay();
515 //=================================================================================
516 // function : ReverseAngle1()
517 // purpose : 'state' not used here
518 //=================================================================================
519 void TransformationGUI_MultiTranslationDlg::ReverseAngle1(int state)
522 if(myConstructorId == 0) {
523 GroupPoints->SpinBox_DX->SetValue(myStep1);
524 if(myOkBase && myOkDir1)
525 this->MakeMultiTranslationSimulationAndDisplay();
527 else if(myConstructorId == 1) {
528 GroupDimensions->SpinBox_DX1->SetValue(myStep1);
529 if(myOkBase && myOkDir1 && myOkDir2)
530 this->MakeMultiTranslationSimulationAndDisplay();
536 //=================================================================================
537 // function : ReverseAngle2()
538 // purpose : 'state' not used here
539 //=================================================================================
540 void TransformationGUI_MultiTranslationDlg::ReverseAngle2(int state)
543 GroupDimensions->SpinBox_DX2->SetValue(myStep2);
544 if(myOkBase && myOkDir1 && myOkDir2)
545 MakeMultiTranslationSimulationAndDisplay();
550 //=================================================================================
551 // function : MakeMultiTranslationSimulationAndDisplay()
553 //=================================================================================
554 void TransformationGUI_MultiTranslationDlg::MakeMultiTranslationSimulationAndDisplay()
556 myGeomBase->EraseSimulationShape();
557 mySimulationTopoDs.Nullify();
560 Standard_Real DX, DY, DZ;
561 gp_Trsf theTransformation;
563 TopoDS_Compound compound;
566 B.MakeCompound(compound);
569 BRepGProp::LinearProperties(myBase, System);
570 gp_Pnt myPoint = System.CentreOfMass();
571 TopoDS_Shape S = BRepBuilderAPI_MakeVertex(myPoint).Shape();
573 switch (myConstructorId)
580 for(i = 0; i < myNbTimes1; i++) {
581 DX = i * myStep1 * Vec.X();
582 DY = i * myStep1 * Vec.Y();
583 DZ = i * myStep1 * Vec.Z();
584 myVec.SetCoord(DX, DY, DZ);
586 theTransformation.SetTranslation(myVec);
587 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
588 B.Add(compound, myBRepTransformation.Shape());
590 mySimulationTopoDs = compound;
591 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
601 for(i = 0; i < myNbTimes1; i++) {
602 for(j = 0; j < myNbTimes2; j++) {
603 DX = i * myStep1 * Vec1.X() + j * myStep2 * Vec2.X();
604 DY = i * myStep1 * Vec1.Y() + j * myStep2 * Vec2.Y();
605 DZ = i * myStep1 * Vec1.Z() + j * myStep2 * Vec2.Z();
606 myVec.SetCoord(DX, DY, DZ);
608 theTransformation.SetTranslation(myVec);
609 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
610 B.Add(compound, myBRepTransformation.Shape());
613 mySimulationTopoDs = compound;
614 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
619 catch(Standard_Failure) {
620 MESSAGE("Exception catched in MakeMultitranslationSimulationAndDisplay");