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_MultiRotationDlg.h"
32 #include <Precision.hxx>
33 #include <BRepBuilderAPI_MakeVertex.hxx>
34 #include <GeomAPI_ProjectPointOnCurve.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 <Geom_Line.hxx>
41 #include <BRepBuilderAPI_Transform.hxx>
42 #include "QAD_Config.h"
44 #include "utilities.h"
48 //=================================================================================
49 // class : TransformationGUI_MultiRotationDlg()
50 // purpose : Constructs a TransformationGUI_MultiRotationDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // TRUE to construct a modal dialog.
54 //=================================================================================
55 TransformationGUI_MultiRotationDlg::TransformationGUI_MultiRotationDlg(QWidget* parent, const char* name, TransformationGUI* theTransformationGUI, SALOME_Selection* Sel, bool modal, WFlags fl)
56 :GEOMBase_Skeleton(parent, name, Sel, modal, WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu)
58 QPixmap image0(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_SIMPLE")));
59 QPixmap image1(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_DLG_MULTIROTATION_DOUBLE")));
60 QPixmap image2(QAD_Desktop::getResourceManager()->loadPixmap("GEOM",tr("ICON_SELECT")));
62 setCaption(tr("GEOM_MULTIROTATION_TITLE"));
64 /***************************************************************/
65 GroupConstructors->setTitle(tr("GEOM_MULTIROTATION"));
66 RadioButton1->setPixmap(image0);
67 RadioButton2->setPixmap(image1);
68 RadioButton3->close(TRUE);
70 GroupPoints = new DlgRef_2Sel1Spin(this, "GroupPoints");
71 GroupPoints->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_SIMPLE"));
72 GroupPoints->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
73 GroupPoints->TextLabel2->setText(tr("GEOM_VECTOR"));
74 GroupPoints->TextLabel3->setText(tr("GEOM_NB_TIMES"));
75 GroupPoints->PushButton1->setPixmap(image2);
76 GroupPoints->PushButton2->setPixmap(image2);
78 GroupDimensions = new DlgRef_2Sel4Spin1Check(this, "GroupDimensions");
79 GroupDimensions->GroupBox1->setTitle(tr("GEOM_MULTIROTATION_DOUBLE"));
80 GroupDimensions->TextLabel1->setText(tr("GEOM_MAIN_OBJECT"));
81 GroupDimensions->TextLabel2->setText(tr("GEOM_VECTOR"));
82 GroupDimensions->TextLabel3->setText(tr("GEOM_ANGLE"));
83 GroupDimensions->TextLabel4->setText(tr("GEOM_NB_TIMES"));
84 GroupDimensions->TextLabel5->setText(tr("GEOM_STEP"));
85 GroupDimensions->TextLabel6->setText(tr("GEOM_NB_TIMES"));
86 GroupDimensions->CheckButton1->setText(tr("GEOM_REVERSE"));
87 GroupDimensions->PushButton1->setPixmap(image2);
88 GroupDimensions->PushButton2->setPixmap(image2);
90 Layout1->addWidget(GroupPoints, 1, 0);
91 Layout1->addWidget(GroupDimensions, 1, 0);
92 /***************************************************************/
95 myTransformationGUI = theTransformationGUI;
100 //=================================================================================
101 // function : ~TransformationGUI_MultiRotationDlg()
102 // purpose : Destroys the object and frees any allocated resources
103 //=================================================================================
104 TransformationGUI_MultiRotationDlg::~TransformationGUI_MultiRotationDlg()
106 // no need to delete child widgets, Qt does it all for us
110 //=================================================================================
113 //=================================================================================
114 void TransformationGUI_MultiRotationDlg::Init()
118 myEditCurrentArgument = GroupPoints->LineEdit1;
124 myOkBase = myOkDir = false;
126 myEdgeFilter = new GEOM_ShapeTypeFilter(TopAbs_EDGE, myGeom);
128 /* Get setting of step value from file configuration */
129 QString St = QAD_CONFIG->getSetting("Geometry:SettingsGeomStep");
130 step = St.toDouble();
132 double SpecificStep1 = 5;
133 double SpecificStep2 = 1;
134 /* min, max, step and decimals for spin boxes & initial values */
135 GroupPoints->SpinBox_DX->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
136 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
138 GroupDimensions->SpinBox_DX1->RangeStepAndValidator(-999.999, 999.999, SpecificStep1, 3);
139 GroupDimensions->SpinBox_DY1->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
140 GroupDimensions->SpinBox_DX2->RangeStepAndValidator(-999.999, 999.999, step, 3);
141 GroupDimensions->SpinBox_DY2->RangeStepAndValidator(1.0, 999.999, SpecificStep2, 3);
142 GroupDimensions->SpinBox_DX1->SetValue(myAng);
143 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
144 GroupDimensions->SpinBox_DX2->SetValue(myStep);
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()));
157 connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
158 connect(GroupPoints->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
159 connect(GroupDimensions->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
160 connect(GroupDimensions->LineEdit2, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed()));
162 connect(GroupPoints->SpinBox_DX, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
163 connect(GroupDimensions->SpinBox_DX1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
164 connect(GroupDimensions->SpinBox_DY1, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
165 connect(GroupDimensions->SpinBox_DX2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
166 connect(GroupDimensions->SpinBox_DY2, SIGNAL(valueChanged(double)), this, SLOT(ValueChangedInSpinBox(double)));
168 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupPoints->SpinBox_DX, SLOT(SetStep(double)));
169 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX1, SLOT(SetStep(double)));
170 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY1, SLOT(SetStep(double)));
171 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DX2, SLOT(SetStep(double)));
172 connect(myGeomGUI, SIGNAL(SignalDefaultStepValueChanged(double)), GroupDimensions->SpinBox_DY2, SLOT(SetStep(double)));
174 connect(GroupDimensions->CheckButton1, SIGNAL(stateChanged(int)), this, SLOT(ReverseAngle(int)));
176 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
178 /* displays Dialog */
179 GroupDimensions->hide();
187 //=================================================================================
188 // function : ConstructorsClicked()
189 // purpose : Radio button management
190 //=================================================================================
191 void TransformationGUI_MultiRotationDlg::ConstructorsClicked(int constructorId)
193 myConstructorId = constructorId;
194 mySelection->ClearFilters();
195 myGeomBase->EraseSimulationShape();
196 mySimulationTopoDs.Nullify();
197 disconnect(mySelection, 0, this, 0);
202 myOkBase = myOkDir = false;
204 switch (constructorId)
206 case 0: /* Rotate simple */
208 GroupDimensions->hide();
212 myEditCurrentArgument = GroupPoints->LineEdit1;
213 GroupPoints->LineEdit1->setText("");
214 GroupPoints->LineEdit2->setText("");
216 GroupPoints->SpinBox_DX->SetValue(myNbTimes1);
218 /* filter for next selection */
219 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
222 case 1: /* Rotate double */
226 GroupDimensions->show();
228 myEditCurrentArgument = GroupDimensions->LineEdit1;
229 GroupDimensions->LineEdit1->setText("");
230 GroupDimensions->LineEdit2->setText("");
232 GroupDimensions->SpinBox_DX1->SetValue(myAng);
233 GroupDimensions->SpinBox_DY1->SetValue(myNbTimes1);
234 GroupDimensions->SpinBox_DX2->SetValue(myStep);
235 GroupDimensions->SpinBox_DY2->SetValue(myNbTimes2);
237 /* filter for next selection */
238 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
246 //=================================================================================
247 // function : ClickOnOk()
249 //=================================================================================
250 void TransformationGUI_MultiRotationDlg::ClickOnOk()
252 this->ClickOnApply();
258 //=================================================================================
259 // function : ClickOnApply()
261 //=================================================================================
262 void TransformationGUI_MultiRotationDlg::ClickOnApply()
264 buttonApply->setFocus();
265 QAD_Application::getDesktop()->putInfo(tr(""));
266 if (mySimulationTopoDs.IsNull())
268 myGeomBase->EraseSimulationShape();
269 mySimulationTopoDs.Nullify();
271 if(myConstructorId == 0) {
272 if(myOkBase && myOkDir)
273 myTransformationGUI->MakeMultiRotation1DAndDisplay(myGeomShape, myDir, myLoc, myNbTimes1);
275 else if(myConstructorId == 1) {
276 if(myOkBase && myOkDir)
277 myTransformationGUI->MakeMultiRotation2DAndDisplay(myGeomShape, myDir, myLoc, myAng, myNbTimes1, myStep, myNbTimes2);
283 //=================================================================================
284 // function : SelectionIntoArgument()
285 // purpose : Called when selection as changed or other case
286 //=================================================================================
287 void TransformationGUI_MultiRotationDlg::SelectionIntoArgument()
289 myGeomBase->EraseSimulationShape();
290 mySimulationTopoDs.Nullify();
291 myEditCurrentArgument->setText("");
292 QString aString = ""; /* name of selection */
294 int nbSel = myGeomBase->GetNameOfSelectedIObjects(mySelection, aString);
296 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1)
298 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2)
305 Standard_Boolean testResult;
306 Handle(SALOME_InteractiveObject) IO = mySelection->firstIObject();
307 if(!myGeomBase->GetTopoFromSelection(mySelection, S))
310 if(myEditCurrentArgument == GroupPoints->LineEdit1 || myEditCurrentArgument == GroupDimensions->LineEdit1) {
311 myGeomShape = myGeomBase->ConvertIOinGEOMShape(IO, testResult);
314 myEditCurrentArgument->setText(aString);
318 else if(myEditCurrentArgument == GroupPoints->LineEdit2 || myEditCurrentArgument == GroupDimensions->LineEdit2) {
319 BRepAdaptor_Curve curv(TopoDS::Edge(S));
320 myDir = curv.Line().Direction();
321 myLoc = curv.Line().Location();
322 myEditCurrentArgument->setText(aString);
326 if(myOkBase && myOkDir)
327 this->MakeMultiRotationSimulationAndDisplay();
332 //=================================================================================
333 // function : SetEditCurrentArgument()
335 //=================================================================================
336 void TransformationGUI_MultiRotationDlg::SetEditCurrentArgument()
338 QPushButton* send = (QPushButton*)sender();
339 mySelection->ClearFilters();
341 if(send == GroupPoints->PushButton1) {
342 GroupPoints->LineEdit1->setFocus();
343 myEditCurrentArgument = GroupPoints->LineEdit1;
345 else if(send == GroupPoints->PushButton2) {
346 GroupPoints->LineEdit2->setFocus();
347 myEditCurrentArgument = GroupPoints->LineEdit2;
348 mySelection->AddFilter(myEdgeFilter);
350 else if(send == GroupDimensions->PushButton1) {
351 GroupDimensions->LineEdit1->setFocus();
352 myEditCurrentArgument = GroupDimensions->LineEdit1;
354 else if(send == GroupDimensions->PushButton2) {
355 GroupDimensions->LineEdit2->setFocus();
356 myEditCurrentArgument = GroupDimensions->LineEdit2;
357 mySelection->AddFilter(myEdgeFilter);
359 this->SelectionIntoArgument();
365 //=================================================================================
366 // function : LineEditReturnPressed()
368 //=================================================================================
369 void TransformationGUI_MultiRotationDlg::LineEditReturnPressed()
371 QLineEdit* send = (QLineEdit*)sender();
372 if(send == GroupPoints->LineEdit1)
373 myEditCurrentArgument = GroupPoints->LineEdit1;
374 else if (send == GroupPoints->LineEdit2)
375 myEditCurrentArgument = GroupPoints->LineEdit2;
376 else if (send == GroupDimensions->LineEdit1)
377 myEditCurrentArgument = GroupDimensions->LineEdit1;
378 else if (send == GroupDimensions->LineEdit2)
379 myEditCurrentArgument = GroupDimensions->LineEdit2;
383 GEOMBase_Skeleton::LineEditReturnPressed();
388 //=================================================================================
389 // function : ActivateThisDialog()
391 //=================================================================================
392 void TransformationGUI_MultiRotationDlg::ActivateThisDialog()
394 GEOMBase_Skeleton::ActivateThisDialog();
395 connect(mySelection, SIGNAL(currentSelectionChanged()), this, SLOT(SelectionIntoArgument()));
397 if(myConstructorId == 0) {
398 GroupPoints->LineEdit1->setFocus();
399 myEditCurrentArgument = GroupPoints->LineEdit1;
401 else if(myConstructorId == 1) {
402 GroupDimensions->LineEdit1->setFocus();
403 myEditCurrentArgument = GroupDimensions->LineEdit1;
406 if(!mySimulationTopoDs.IsNull())
407 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
412 //=================================================================================
413 // function : enterEvent()
415 //=================================================================================
416 void TransformationGUI_MultiRotationDlg::enterEvent(QEvent* e)
418 if (GroupConstructors->isEnabled())
420 this->ActivateThisDialog();
425 //=================================================================================
426 // function : ValueChangedInSpinBox()
428 //=================================================================================
429 void TransformationGUI_MultiRotationDlg::ValueChangedInSpinBox(double newValue)
431 myGeomBase->EraseSimulationShape();
432 mySimulationTopoDs.Nullify();
433 QObject* send = (QObject*)sender();
435 if(send == GroupPoints->SpinBox_DX || send == GroupDimensions->SpinBox_DY1)
436 myNbTimes1 = (int)newValue;
437 else if(send == GroupDimensions->SpinBox_DX1)
439 else if(send == GroupDimensions->SpinBox_DX2)
441 else if(send == GroupDimensions->SpinBox_DY2)
442 myNbTimes2 = (int)newValue;
444 if(myOkBase && myOkDir)
445 this->MakeMultiRotationSimulationAndDisplay();
450 //=================================================================================
451 // function : ReverseAngle()
452 // purpose : 'state' not used here
453 //=================================================================================
454 void TransformationGUI_MultiRotationDlg::ReverseAngle(int state)
457 if(myConstructorId == 0)
458 GroupPoints->SpinBox_DX->SetValue(myAng);
459 else if(myConstructorId == 1)
460 GroupDimensions->SpinBox_DX1->SetValue(myAng);
462 if(myOkBase && myOkDir)
463 this->MakeMultiRotationSimulationAndDisplay();
468 //=================================================================================
469 // function : MakeMultiRotationSimulationAndDisplay()
471 //=================================================================================
472 void TransformationGUI_MultiRotationDlg::MakeMultiRotationSimulationAndDisplay()
474 myGeomBase->EraseSimulationShape();
475 mySimulationTopoDs.Nullify();
478 Standard_Real DX, DY, DZ;
479 gp_Trsf theTransformation;
480 gp_Trsf theTransformation1;
481 gp_Trsf theTransformation2;
484 TopoDS_Compound compound;
487 B.MakeCompound(compound);
489 if(myBase.ShapeType() == TopAbs_VERTEX)
490 myGeomBase->VertexToPoint(myBase, myPoint);
491 else if(myBase.ShapeType() == TopAbs_EDGE || myBase.ShapeType() == TopAbs_WIRE) {
492 BRepGProp::LinearProperties(myBase, System);
493 myPoint = System.CentreOfMass();
495 else if(myBase.ShapeType() == TopAbs_FACE || myBase.ShapeType() == TopAbs_SHELL) {
496 BRepGProp::SurfaceProperties(myBase, System);
497 myPoint = System.CentreOfMass();
500 BRepGProp::VolumeProperties(myBase, System);
501 myPoint = System.CentreOfMass();
504 TopoDS_Shape S = BRepBuilderAPI_MakeVertex(myPoint).Shape();
507 switch (myConstructorId)
511 gp_Ax1 AX1(myLoc, myDir);
512 Standard_Real angle = 360/myNbTimes1;
513 for(i = 0; i < myNbTimes1; i++) {
514 theTransformation.SetRotation(AX1, i*angle*PI180);
515 BRepBuilderAPI_Transform myBRepTransformation(S, theTransformation, Standard_False);
516 B.Add(compound, myBRepTransformation.Shape());
518 mySimulationTopoDs = compound;
519 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
524 gp_Ax1 AX2(myLoc, myDir);
525 Handle(Geom_Line) Line = new Geom_Line(AX2);
526 gp_Pnt P2 = GeomAPI_ProjectPointOnCurve(myPoint, Line);
527 if(myPoint.IsEqual(P2, Precision::Confusion()))
530 gp_Vec Vec(P2, myPoint);
533 for(i = 0; i < myNbTimes2; i++) {
534 for(j = 0; j < myNbTimes1; j++) {
535 DX = i * myStep * Vec.X();
536 DY = i * myStep * Vec.Y();
537 DZ = i * myStep * Vec.Z();
538 myVec.SetCoord(DX, DY, DZ);
540 theTransformation1.SetTranslation(myVec);
541 theTransformation2.SetRotation(AX2, j*myAng*PI180);
542 BRepBuilderAPI_Transform myBRepTransformation1(S, theTransformation1, Standard_False);
543 BRepBuilderAPI_Transform myBRepTransformation2(myBRepTransformation1.Shape(), theTransformation2, Standard_False);
544 B.Add(compound, myBRepTransformation2.Shape());
547 mySimulationTopoDs = compound;
548 myGeomBase->DisplaySimulationShape(mySimulationTopoDs);
553 catch(Standard_Failure) {
554 MESSAGE("Exception catched in MakeMultitranslationSimulationAndDisplay");