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
29 #include "TransformationGUI_MultiTranslationDlg.h"
32 #include <BRepBuilderAPI_MakeVertex.hxx>
33 #include <BRepBuilderAPI_Transform.hxx>
34 #include <BRepAdaptor_Curve.hxx>
35 #include <BRep_Builder.hxx>
36 #include <BRepGProp.hxx>
37 #include <GProp_GProps.hxx>
38 #include <TopoDS_Compound.hxx>
39 #include "QAD_Config.h"
41 #include "utilities.h"
45 //=================================================================================
46 // class : TransformationGUI_MultiTranslationDlg()
47 // purpose : Constructs a TransformationGUI_MultiTranslationDlg which is a child of 'parent', with the
48 // name 'name' and widget flags set to 'f'.
49 // The dialog will by default be modeless, unless you set 'modal' to
50 // TRUE to construct a modal dialog.
51 //=================================================================================
52 TransformationGUI_MultiTranslationDlg::TransformationGUI_MultiTranslationDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
53 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
55 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_MULTITRANSLATION_SIMPLE")));
56 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_DLG_MULTITRANSLATION_DOUBLE")));
57 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap( "GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_MULTITRANSLATION_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_MULTITRANSLATION"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_2Sel2Spin1Check(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_SIMPLE"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR_U"));
71 GroupPoints->TextLabel3->setText(tr("GEOM_STEP_U"));
72 GroupPoints->TextLabel4->setText(tr("GEOM_NB_TIMES_U"));
73 GroupPoints->CheckButton1->setText(tr("GEOM_REVERSE_U"));
74 GroupPoints->PushButton1->setPixmap(image2);
75 GroupPoints->PushButton2->setPixmap(image2);
77 GroupDimensions = new DlgRef_3Sel4Spin2Check(this, "GroupDimensions");
78 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTITRANSLATION_DOUBLE"));
79 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
80 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR_U"));
81 GroupDimensions->TextLabel3->setText(tr("GEOM_VECTOR_V"));
82 GroupDimensions->TextLabel4->setText(tr("GEOM_STEP_U"));
83 GroupDimensions->TextLabel5->setText(tr("GEOM_NB_TIMES_U"));
84 GroupDimensions->TextLabel6->setText(tr("GEOM_STEP_V"));
85 GroupDimensions->TextLabel7->setText(tr("GEOM_NB_TIMES_V"));
86 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE_U"));
87 GroupDimensions->CheckButton2->setText(tr("GEOM_REVERSE_V"));
88 GroupDimensions->PushButton1->setPixmap(image2);
89 GroupDimensions->PushButton2->setPixmap(image2);
90 GroupDimensions->PushButton3->setPixmap(image2);
92 Layout1->addWidget(GroupPoints, 1, 0);
93 Layout1->addWidget(GroupDimensions, 1, 0);
94 /***************************************************************/
97 myTransformationGUI = theTransformationGUI;
102 //=================================================================================
103 // function : ~TransformationGUI_MultiTranslationDlg()
104 // purpose : Destroys the object and frees any allocated resources
105 //=================================================================================
106 TransformationGUI_MultiTranslationDlg::~TransformationGUI_MultiTranslationDlg()
108 // no need to delete child widgets, Qt does it all for us
112 //=================================================================================
115 //=================================================================================
116 void TransformationGUI_MultiTranslationDlg::Init()
120 myEditCurrentArgument = GroupPoints->LineEdit1;
126 myOkBase = myOkDir1 = myOkDir2 = false;
128 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
130 /* Get setting of step value from file configuration */
131 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
132 step = St.toDouble();
134 double SpecificStep = 1;
135 /* min, max, step and decimals for spin boxes & initial values */
136 GroupPoints->SpinBox_DX->RangeStepAndValidator(-999.999, 999.999, step, 3);
137 GroupPoints->SpinBox_DY->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
138 GroupPoints->SpinBox_DX->SetValue(myStep1);
139 GroupPoints->SpinBox_DY->SetValue(myNbTimes1);
141 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, step, 3);
142 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
143 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
144 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep, 3);
145 GroupDimensions->SpinBox_DX1->SetValue(myStep1);
146 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
147 GroupDimensions->SpinBox_DX2->SetValue(myStep2);
148 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
150 /* signals and slots connections */
151 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
152 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
153 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
155 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
156 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
157 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
158 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
159 connect(GroupDimensions->PushButton3, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
161 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
163 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
164 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
165 connect(GroupDimensions->LineEdit3, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
167 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168 connect(GroupPoints->SpinBox_DY, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
169 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
170 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
171 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
172 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
174 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
175 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DY, SLOT(SetStep(double)));
176 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
177 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
178 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
179 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
181 connect(GroupPoints->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle1(int)));
182 connect(GroupDimensions->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle1(int)));
183 connect(GroupDimensions->CheckButton2, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle2(int)));
185 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
187 /* displays Dialog */
188 GroupDimensions->hide();
196 //=================================================================================
197 // function : ConstructorsClicked()
198 // purpose : Radio button management
199 //=================================================================================
200 void TransformationGUI_MultiTranslationDlg::ConstructorsClicked(int constructorId)
202 myConstructorId = constructorId;
203 mySelection->ClearFilters();
204 myGeomBase->EraseSimulationShape();
205 mySimulationTopoDs.Nullify();
206 disconnect(mySelection, 0, this, 0);
211 myOkBase = myOkDir1 = myOkDir2 = false;
213 switch (constructorId)
215 case 0: /* Translate simple */
217 GroupDimensions->hide();
221 myEditCurrentArgument = GroupPoints->LineEdit1;
222 GroupPoints->LineEdit1->setText("");
223 GroupPoints->LineEdit2->setText("");
225 GroupPoints->SpinBox_DX->SetValue(myStep1);
226 GroupPoints->SpinBox_DY->SetValue(myNbTimes1);
228 /* filter for next selection */
229 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
232 case 1: /* Translate double */
236 GroupDimensions->show();
238 myEditCurrentArgument = GroupDimensions->LineEdit1;
239 GroupDimensions->LineEdit1->setText("");
240 GroupDimensions->LineEdit2->setText("");
241 GroupDimensions->LineEdit3->setText("");
243 GroupDimensions->SpinBox_DX1->SetValue(myStep1);
244 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
245 GroupDimensions->SpinBox_DX2->SetValue(myStep2);
246 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
248 /* filter for next selection */
249 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
257 //=================================================================================
258 // function : ClickOnOk()
260 //=================================================================================
261 void TransformationGUI_MultiTranslationDlg::ClickOnOk()
263 this->ClickOnApply();
269 //=================================================================================
270 // function : ClickOnApply()
272 //=================================================================================
273 void TransformationGUI_MultiTranslationDlg::ClickOnApply()
275 buttonApply->setFocus();
276 QAD_Application::getDesktop()->putInfo(tr(""));
277 if (mySimulationTopoDs.IsNull())
279 myGeomBase->EraseSimulationShape();
280 mySimulationTopoDs.Nullify();
282 if(myConstructorId == 0) {
283 if(myOkBase && myOkDir1)
284 myTransformationGUI->MakeMultiTranslation1DAndDisplay(myGeomShape, myDir1, myStep1, myNbTimes1);
286 else if(myConstructorId == 1) {
287 if(myOkBase && myOkDir1 && myOkDir2)
288 myTransformationGUI->MakeMultiTranslation2DAndDisplay(myGeomShape, myDir1, myStep1, myNbTimes1, myDir2, myStep2, myNbTimes2);
294 //=================================================================================
295 // function : SelectionIntoArgument()
296 // purpose : Called when selection as changed or other case
297 //=================================================================================
298 void TransformationGUI_MultiTranslationDlg::SelectionIntoArgument()
300 myGeomBase->EraseSimulationShape();
301 mySimulationTopoDs.Nullify();
302 myEditCurrentArgument->setText("");
303 QString aString = ""; /* name of selection */
305 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
307 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
309 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
311 else if(myEditCurrentArgument == GroupDimensions->LineEdit3)
318 Standard_Boolean testResult;
319 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
320 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
323 switch(myConstructorId)
327 if(myEditCurrentArgument == GroupPoints->LineEdit1) {
328 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
331 myEditCurrentArgument->setText(aString);
335 else if(myEditCurrentArgument == GroupPoints->LineEdit2) {
336 BRepAdaptor_Curve curv(TopoDS::Edge(S));
337 myDir1 = curv.Line().Direction();
338 myEditCurrentArgument->setText(aString);
342 if(myOkBase && myOkDir1)
343 this->MakeMultiTranslationSimulationAndDisplay();
348 if(myEditCurrentArgument == GroupDimensions->LineEdit1) {
349 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
352 myEditCurrentArgument->setText(aString);
356 else if(myEditCurrentArgument == GroupDimensions->LineEdit2) {
357 BRepAdaptor_Curve curv(TopoDS::Edge(S));
358 myDir1 = curv.Line().Direction();
359 myEditCurrentArgument->setText(aString);
362 else if(myEditCurrentArgument == GroupDimensions->LineEdit3) {
363 BRepAdaptor_Curve curv(TopoDS::Edge(S));
364 myDir2 = curv.Line().Direction();
365 myEditCurrentArgument->setText(aString);
369 if(myOkBase && myOkDir1 && myOkDir2)
370 this->MakeMultiTranslationSimulationAndDisplay();
378 //=================================================================================
379 // function : SetEditCurrentArgument()
381 //=================================================================================
382 void TransformationGUI_MultiTranslationDlg::SetEditCurrentArgument()
384 QPushButton* send = (QPushButton*)sender();
385 mySelection->ClearFilters();
387 if(send == GroupPoints->PushButton1) {
388 GroupPoints->LineEdit1->setFocus();
389 myEditCurrentArgument = GroupPoints->LineEdit1;
391 else if(send == GroupPoints->PushButton2) {
392 GroupPoints->LineEdit2->setFocus();
393 myEditCurrentArgument = GroupPoints->LineEdit2;
394 mySelection->AddFilter(myEdgeFilter);
396 else if(send == GroupDimensions->PushButton1) {
397 GroupDimensions->LineEdit1->setFocus();
398 myEditCurrentArgument = GroupDimensions->LineEdit1;
400 else if(send == GroupDimensions->PushButton2) {
401 GroupDimensions->LineEdit2->setFocus();
402 myEditCurrentArgument = GroupDimensions->LineEdit2;
403 mySelection->AddFilter(myEdgeFilter);
405 else if(send == GroupDimensions->PushButton3) {
406 GroupDimensions->LineEdit3->setFocus();
407 myEditCurrentArgument = GroupDimensions->LineEdit3;
408 mySelection->AddFilter(myEdgeFilter);
410 this->SelectionIntoArgument();
416 //=================================================================================
417 // function : LineEditReturnPressed()
419 //=================================================================================
420 void TransformationGUI_MultiTranslationDlg::LineEditReturnPressed()
422 QLineEdit* send = (QLineEdit*)sender();
423 if(send == GroupPoints->LineEdit1)
424 myEditCurrentArgument = GroupPoints->LineEdit1;
425 else if (send == GroupPoints->LineEdit2)
426 myEditCurrentArgument = GroupPoints->LineEdit2;
427 else if (send == GroupDimensions->LineEdit1)
428 myEditCurrentArgument = GroupDimensions->LineEdit1;
429 else if (send == GroupDimensions->LineEdit2)
430 myEditCurrentArgument = GroupDimensions->LineEdit2;
431 else if (send == GroupDimensions->LineEdit3)
432 myEditCurrentArgument = GroupDimensions->LineEdit3;
436 GEOMBase_Skeleton::LineEditReturnPressed();
441 //=================================================================================
442 // function : ActivateThisDialog()
444 //=================================================================================
445 void TransformationGUI_MultiTranslationDlg::ActivateThisDialog()
447 GEOMBase_Skeleton::ActivateThisDialog();
448 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
450 if(myConstructorId == 0) {
451 GroupPoints->LineEdit1->setFocus();
452 myEditCurrentArgument = GroupPoints->LineEdit1;
454 else if(myConstructorId == 1) {
455 GroupDimensions->LineEdit1->setFocus();
456 myEditCurrentArgument = GroupDimensions->LineEdit1;
459 if(!mySimulationTopoDs.IsNull())
460 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
465 //=================================================================================
466 // function : enterEvent()
468 //=================================================================================
469 void TransformationGUI_MultiTranslationDlg::enterEvent(QEvent* e)
471 if (GroupConstructors->isEnabled())
473 this->ActivateThisDialog();
478 //=================================================================================
479 // function : ValueChangedInSpinBox()
481 //=================================================================================
482 void TransformationGUI_MultiTranslationDlg::ValueChangedInSpinBox(double newValue)
484 myGeomBase->EraseSimulationShape();
485 mySimulationTopoDs.Nullify();
486 QObject* send = (QObject*)sender();
488 switch(myConstructorId)
492 if(send == GroupPoints->SpinBox_DX)
494 else if(send == GroupPoints->SpinBox_DY)
495 myNbTimes1 = (int)newValue;
496 if(myOkBase && myOkDir1)
497 this->MakeMultiTranslationSimulationAndDisplay();
502 if(send == GroupDimensions->SpinBox_DX1)
504 else if(send == GroupDimensions->SpinBox_DY1)
505 myNbTimes1 = (int)newValue;
506 else if(send == GroupDimensions->SpinBox_DX2)
508 else if(send == GroupDimensions->SpinBox_DY2)
509 myNbTimes2 = (int)newValue;
510 if(myOkBase && myOkDir1 && myOkDir2)
511 this->MakeMultiTranslationSimulationAndDisplay();
519 //=================================================================================
520 // function : ReverseAngle1()
521 // purpose : 'state' not used here
522 //=================================================================================
523 void TransformationGUI_MultiTranslationDlg::ReverseAngle1(int state)
526 if(myConstructorId == 0) {
527 GroupPoints->SpinBox_DX->SetValue(myStep1);
528 if(myOkBase && myOkDir1)
529 this->MakeMultiTranslationSimulationAndDisplay();
531 else if(myConstructorId == 1) {
532 GroupDimensions->SpinBox_DX1->SetValue(myStep1);
533 if(myOkBase && myOkDir1 && myOkDir2)
534 this->MakeMultiTranslationSimulationAndDisplay();
540 //=================================================================================
541 // function : ReverseAngle2()
542 // purpose : 'state' not used here
543 //=================================================================================
544 void TransformationGUI_MultiTranslationDlg::ReverseAngle2(int state)
547 GroupDimensions->SpinBox_DX2->SetValue(myStep2);
548 if(myOkBase && myOkDir1 && myOkDir2)
549 MakeMultiTranslationSimulationAndDisplay();
554 //=================================================================================
555 // function : MakeMultiTranslationSimulationAndDisplay()
557 //=================================================================================
558 void TransformationGUI_MultiTranslationDlg::MakeMultiTranslationSimulationAndDisplay()
560 myGeomBase->EraseSimulationShape();
561 mySimulationTopoDs.Nullify();
564 Standard_Real DX, DY, DZ;
565 gp_Trsf theTransformation;
567 TopoDS_Compound compound;
570 B.MakeCompound(compound);
573 BRepGProp::LinearProperties(myBase, System);
574 gp_Pnt myPoint = System.CentreOfMass();
575 TopoDS_Shape S = BRepBuilderAPI_MakeVertex(myPoint).Shape();
577 switch (myConstructorId)
584 for(i = 0; i < myNbTimes1; i++) {
585 DX = i * myStep1 * Vec.X();
586 DY = i * myStep1 * Vec.Y();
587 DZ = i * myStep1 * Vec.Z();
588 myVec.SetCoord(DX, DY, DZ);
590 theTransformation.SetTranslation(myVec);
591 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
592 B.Add(compound, myBRepTransformation.Shape());
594 mySimulationTopoDs = compound;
595 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
605 for(i = 0; i < myNbTimes1; i++) {
606 for(j = 0; j < myNbTimes2; j++) {
607 DX = i * myStep1 * Vec1.X() + j * myStep2 * Vec2.X();
608 DY = i * myStep1 * Vec1.Y() + j * myStep2 * Vec2.Y();
609 DZ = i * myStep1 * Vec1.Z() + j * myStep2 * Vec2.Z();
610 myVec.SetCoord(DX, DY, DZ);
612 theTransformation.SetTranslation(myVec);
613 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
614 B.Add(compound, myBRepTransformation.Shape());
617 mySimulationTopoDs = compound;
618 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
623 catch(Standard_Failure) {
624 MESSAGE("Exception catched in MakeMultitranslationSimulationAndDisplay");