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_MultiRotationDlg.h"
33 #include <Precision.hxx>
34 #include <BRepBuilderAPI_MakeVertex.hxx>
35 #include <GeomAPI_ProjectPointOnCurve.hxx>
36 #include <BRepAdaptor_Curve.hxx>
37 #include <BRep_Builder.hxx>
38 #include <BRepGProp.hxx>
39 #include <GProp_GProps.hxx>
40 #include <TopoDS_Compound.hxx>
41 #include <Geom_Line.hxx>
42 #include <BRepBuilderAPI_Transform.hxx>
43 #include "QAD_Config.h"
45 //=================================================================================
46 // class : TransformationGUI_MultiRotationDlg()
47 // purpose : Constructs a TransformationGUI_MultiRotationDlg 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_MultiRotationDlg::TransformationGUI_MultiRotationDlg(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_MULTIROTATION_SIMPLE")));
56 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
57 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
59 setCaption(tr("GEOM_MULTIROTATION_TITLE"));
61 /***************************************************************/
62 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
63 RadioButton1->setPixmap(image0);
64 RadioButton2->setPixmap(image1);
65 RadioButton3->close(TRUE);
67 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
68 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
69 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
70 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
71 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
72 GroupPoints->PushButton1->setPixmap(image2);
73 GroupPoints->PushButton2->setPixmap(image2);
75 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
76 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
77 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
78 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
79 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
80 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
81 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
82 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
83 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
84 GroupDimensions->PushButton1->setPixmap(image2);
85 GroupDimensions->PushButton2->setPixmap(image2);
87 Layout1->addWidget(GroupPoints, 1, 0);
88 Layout1->addWidget(GroupDimensions, 1, 0);
89 /***************************************************************/
92 myTransformationGUI = theTransformationGUI;
97 //=================================================================================
98 // function : ~TransformationGUI_MultiRotationDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
103 // no need to delete child widgets, Qt does it all for us
107 //=================================================================================
110 //=================================================================================
111 void TransformationGUI_MultiRotationDlg::Init()
115 myEditCurrentArgument = GroupPoints->LineEdit1;
121 myOkBase = myOkDir = false;
123 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
125 /* Get setting of step value from file configuration */
126 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
127 step = St.toDouble();
129 double SpecificStep1 = 5;
130 double SpecificStep2 = 1;
131 /* min, max, step and decimals for spin boxes & initial values */
132 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
133 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
135 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, SpecificStep1, 3);
136 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
137 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
138 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
139 GroupDimensions->SpinBox_DX1->SetValue(myAng);
140 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
141 GroupDimensions->SpinBox_DX2->SetValue(myStep);
142 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
144 /* signals and slots connections */
145 connect(buttonOk, SIGNAL(clicked()), this, SLOT(ClickOnOk()));
146 connect(buttonApply, SIGNAL(clicked()), this, SLOT(ClickOnApply()));
147 connect(GroupConstructors, SIGNAL(clicked(int)), this, SLOT(ConstructorsClicked(int)));
149 connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
150 connect(GroupPoints->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
151 connect(GroupDimensions->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
152 connect(GroupDimensions->PushButton2, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument()));
154 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
155 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
156 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
157 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
160 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
161 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
162 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
165 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
166 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
167 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
168 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
169 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
171 connect(GroupDimensions->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
173 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
175 /* displays Dialog */
176 GroupDimensions->hide();
184 //=================================================================================
185 // function : ConstructorsClicked()
186 // purpose : Radio button management
187 //=================================================================================
188 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
190 myConstructorId = constructorId;
191 mySelection->ClearFilters();
192 myGeomBase->EraseSimulationShape();
193 mySimulationTopoDs.Nullify();
194 disconnect(mySelection, 0, this, 0);
199 myOkBase = myOkDir = false;
201 switch (constructorId)
203 case 0: /* Rotate simple */
205 GroupDimensions->hide();
209 myEditCurrentArgument = GroupPoints->LineEdit1;
210 GroupPoints->LineEdit1->setText("");
211 GroupPoints->LineEdit2->setText("");
213 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
215 /* filter for next selection */
216 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
219 case 1: /* Rotate double */
223 GroupDimensions->show();
225 myEditCurrentArgument = GroupDimensions->LineEdit1;
226 GroupDimensions->LineEdit1->setText("");
227 GroupDimensions->LineEdit2->setText("");
229 GroupDimensions->SpinBox_DX1->SetValue(myAng);
230 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
231 GroupDimensions->SpinBox_DX2->SetValue(myStep);
232 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
234 /* filter for next selection */
235 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
243 //=================================================================================
244 // function : ClickOnOk()
246 //=================================================================================
247 void TransformationGUI_MultiRotationDlg::ClickOnOk()
249 this->ClickOnApply();
255 //=================================================================================
256 // function : ClickOnApply()
258 //=================================================================================
259 void TransformationGUI_MultiRotationDlg::ClickOnApply()
261 buttonApply->setFocus();
262 QAD_Application::getDesktop()->putInfo(tr(""));
263 if (mySimulationTopoDs.IsNull())
265 myGeomBase->EraseSimulationShape();
266 mySimulationTopoDs.Nullify();
268 if(myConstructorId == 0) {
269 if(myOkBase && myOkDir)
270 myTransformationGUI->MakeMultiRotation1DAndDisplay(myGeomShape, myDir, myLoc, myNbTimes1);
272 else if(myConstructorId == 1) {
273 if(myOkBase && myOkDir)
274 myTransformationGUI->MakeMultiRotation2DAndDisplay(myGeomShape, myDir, myLoc, myAng, myNbTimes1, myStep, myNbTimes2);
280 //=================================================================================
281 // function : SelectionIntoArgument()
282 // purpose : Called when selection as changed or other case
283 //=================================================================================
284 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
286 myGeomBase->EraseSimulationShape();
287 mySimulationTopoDs.Nullify();
288 myEditCurrentArgument->setText("");
289 QString aString = ""; /* name of selection */
291 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
293 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
295 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
302 Standard_Boolean testResult;
303 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
304 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
307 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1) {
308 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
311 myEditCurrentArgument->setText(aString);
315 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2) {
316 BRepAdaptor_Curve curv(TopoDS::Edge(S));
317 myDir = curv.Line().Direction();
318 myLoc = curv.Line().Location();
319 myEditCurrentArgument->setText(aString);
323 if(myOkBase && myOkDir)
324 this->MakeMultiRotationSimulationAndDisplay();
329 //=================================================================================
330 // function : SetEditCurrentArgument()
332 //=================================================================================
333 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
335 QPushButton* send = (QPushButton*)sender();
336 mySelection->ClearFilters();
338 if(send == GroupPoints->PushButton1) {
339 GroupPoints->LineEdit1->setFocus();
340 myEditCurrentArgument = GroupPoints->LineEdit1;
342 else if(send == GroupPoints->PushButton2) {
343 GroupPoints->LineEdit2->setFocus();
344 myEditCurrentArgument = GroupPoints->LineEdit2;
345 mySelection->AddFilter(myEdgeFilter);
347 else if(send == GroupDimensions->PushButton1) {
348 GroupDimensions->LineEdit1->setFocus();
349 myEditCurrentArgument = GroupDimensions->LineEdit1;
351 else if(send == GroupDimensions->PushButton2) {
352 GroupDimensions->LineEdit2->setFocus();
353 myEditCurrentArgument = GroupDimensions->LineEdit2;
354 mySelection->AddFilter(myEdgeFilter);
356 this->SelectionIntoArgument();
362 //=================================================================================
363 // function : LineEditReturnPressed()
365 //=================================================================================
366 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
368 QLineEdit* send = (QLineEdit*)sender();
369 if(send == GroupPoints->LineEdit1)
370 myEditCurrentArgument = GroupPoints->LineEdit1;
371 else if (send == GroupPoints->LineEdit2)
372 myEditCurrentArgument = GroupPoints->LineEdit2;
373 else if (send == GroupDimensions->LineEdit1)
374 myEditCurrentArgument = GroupDimensions->LineEdit1;
375 else if (send == GroupDimensions->LineEdit2)
376 myEditCurrentArgument = GroupDimensions->LineEdit2;
380 GEOMBase_Skeleton::LineEditReturnPressed();
385 //=================================================================================
386 // function : ActivateThisDialog()
388 //=================================================================================
389 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
391 GEOMBase_Skeleton::ActivateThisDialog();
392 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
394 if(myConstructorId == 0) {
395 GroupPoints->LineEdit1->setFocus();
396 myEditCurrentArgument = GroupPoints->LineEdit1;
398 else if(myConstructorId == 1) {
399 GroupDimensions->LineEdit1->setFocus();
400 myEditCurrentArgument = GroupDimensions->LineEdit1;
403 if(!mySimulationTopoDs.IsNull())
404 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
409 //=================================================================================
410 // function : enterEvent()
412 //=================================================================================
413 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
415 if (GroupConstructors->isEnabled())
417 this->ActivateThisDialog();
422 //=================================================================================
423 // function : ValueChangedInSpinBox()
425 //=================================================================================
426 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
428 myGeomBase->EraseSimulationShape();
429 mySimulationTopoDs.Nullify();
430 QObject* send = (QObject*)sender();
432 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
433 myNbTimes1 = (int)newValue;
434 else if(send == GroupDimensions->SpinBox_DX1)
436 else if(send == GroupDimensions->SpinBox_DX2)
438 else if(send == GroupDimensions->SpinBox_DY2)
439 myNbTimes2 = (int)newValue;
441 if(myOkBase && myOkDir)
442 this->MakeMultiRotationSimulationAndDisplay();
447 //=================================================================================
448 // function : ReverseAngle()
449 // purpose : 'state' not used here
450 //=================================================================================
451 void TransformationGUI_MultiRotationDlg::ReverseAngle(int state)
454 if(myConstructorId == 0)
455 GroupPoints->SpinBox_DX->SetValue(myAng);
456 else if(myConstructorId == 1)
457 GroupDimensions->SpinBox_DX1->SetValue(myAng);
459 if(myOkBase && myOkDir)
460 this->MakeMultiRotationSimulationAndDisplay();
465 //=================================================================================
466 // function : MakeMultiRotationSimulationAndDisplay()
468 //=================================================================================
469 void TransformationGUI_MultiRotationDlg::MakeMultiRotationSimulationAndDisplay()
471 myGeomBase->EraseSimulationShape();
472 mySimulationTopoDs.Nullify();
475 Standard_Real DX, DY, DZ;
476 gp_Trsf theTransformation;
477 gp_Trsf theTransformation1;
478 gp_Trsf theTransformation2;
481 TopoDS_Compound compound;
484 B.MakeCompound(compound);
486 if(myBase.ShapeType() == TopAbs_VERTEX)
487 myGeomBase->VertexToPoint(myBase, myPoint);
488 else if(myBase.ShapeType() == TopAbs_EDGE || myBase.ShapeType() == TopAbs_WIRE) {
489 BRepGProp::LinearProperties(myBase, System);
490 myPoint = System.CentreOfMass();
492 else if(myBase.ShapeType() == TopAbs_FACE || myBase.ShapeType() == TopAbs_SHELL) {
493 BRepGProp::SurfaceProperties(myBase, System);
494 myPoint = System.CentreOfMass();
497 BRepGProp::VolumeProperties(myBase, System);
498 myPoint = System.CentreOfMass();
501 TopoDS_Shape S = BRepBuilderAPI_MakeVertex(myPoint).Shape();
504 switch (myConstructorId)
508 gp_Ax1 AX1(myLoc, myDir);
509 Standard_Real angle = 360/myNbTimes1;
510 for(i = 0; i < myNbTimes1; i++) {
511 theTransformation.SetRotation(AX1, i*angle*PI180);
512 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
513 B.Add(compound, myBRepTransformation.Shape());
515 mySimulationTopoDs = compound;
516 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
521 gp_Ax1 AX2(myLoc, myDir);
522 Handle(Geom_Line) Line = new Geom_Line(AX2);
523 gp_Pnt P2 = GeomAPI_ProjectPointOnCurve(myPoint, Line);
524 if(myPoint.IsEqual(P2, Precision::Confusion()))
527 gp_Vec Vec(P2, myPoint);
530 for(i = 0; i < myNbTimes2; i++) {
531 for(j = 0; j < myNbTimes1; j++) {
532 DX = i * myStep * Vec.X();
533 DY = i * myStep * Vec.Y();
534 DZ = i * myStep * Vec.Z();
535 myVec.SetCoord(DX, DY, DZ);
537 theTransformation1.SetTranslation(myVec);
538 theTransformation2.SetRotation(AX2, j*myAng*PI180);
539 BRepBuilderAPI_Transform myBRepTransformation1(S, theTransformation1, Standard_False);
540 BRepBuilderAPI_Transform myBRepTransformation2(myBRepTransformation1.Shape(), theTransformation2, Standard_False);
541 B.Add(compound, myBRepTransformation2.Shape());
544 mySimulationTopoDs = compound;
545 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
550 catch(Standard_Failure) {
551 MESSAGE("Exception catched in MakeMultitranslationSimulationAndDisplay");